Class: MiniKraken::Core::Arity
- Inherits:
-
Struct
- Object
- Struct
- MiniKraken::Core::Arity
- Defined in:
- lib/mini_kraken/core/arity.rb
Overview
The arity is the number of arguments a relations or a function can take.
Instance Attribute Summary collapse
-
#high ⇒ Object
Returns the value of attribute high.
-
#low ⇒ Object
Returns the value of attribute low.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality check.
-
#binary? ⇒ Boolean
Is the arity set to two?.
-
#match?(aCount) ⇒ Boolean
Does the given argument value fits within the boundary values?.
-
#nullary? ⇒ Boolean
Is the arity set to zero?.
-
#unary? ⇒ Boolean
Is the arity set to one?.
-
#unique? ⇒ Boolean
Is the arity constrained to a single, unique value? In other words, are the low and high bound equal?.
-
#variadic? ⇒ Boolean
Can the arity take arbitrary values?.
Instance Attribute Details
#high ⇒ Object
Returns the value of attribute high
6 7 8 |
# File 'lib/mini_kraken/core/arity.rb', line 6 def high @high end |
#low ⇒ Object
Returns the value of attribute low
6 7 8 |
# File 'lib/mini_kraken/core/arity.rb', line 6 def low @low end |
Instance Method Details
#==(other) ⇒ Boolean
Equality check
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mini_kraken/core/arity.rb', line 51 def ==(other) return true if object_id == other.object_id result = false case other when Arity result = true if (low == other.low) && (high == other.high) when Array result = true if (low == other.first) && (high == other.last) when Integer result = true if (low == other) && (high == other) end result end |
#binary? ⇒ Boolean
Is the arity set to two?
28 29 30 |
# File 'lib/mini_kraken/core/arity.rb', line 28 def binary? unique? && low == 2 end |
#match?(aCount) ⇒ Boolean
Does the given argument value fits within the boundary values?
41 42 43 44 45 46 |
# File 'lib/mini_kraken/core/arity.rb', line 41 def match?(aCount) is_matching = aCount >= low is_matching &&= aCount <= high unless variadic? is_matching end |
#nullary? ⇒ Boolean
Is the arity set to zero?
16 17 18 |
# File 'lib/mini_kraken/core/arity.rb', line 16 def nullary? unique? && low.zero? end |
#unary? ⇒ Boolean
Is the arity set to one?
22 23 24 |
# File 'lib/mini_kraken/core/arity.rb', line 22 def unary? unique? && low == 1 end |
#unique? ⇒ Boolean
Is the arity constrained to a single, unique value? In other words, are the low and high bound equal?
10 11 12 |
# File 'lib/mini_kraken/core/arity.rb', line 10 def unique? low == high end |
#variadic? ⇒ Boolean
Can the arity take arbitrary values?
34 35 36 |
# File 'lib/mini_kraken/core/arity.rb', line 34 def variadic? high == '*' end |