Class: MiniKraken::Core::Specification
- Inherits:
-
Object
- Object
- MiniKraken::Core::Specification
- Defined in:
- lib/mini_kraken/core/specification.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arity ⇒ Arity
readonly
Arity = allowed number of arguments.
-
#name ⇒ String
readonly
Name of the specification object.
Instance Method Summary collapse
-
#check_arity(actuals) ⇒ Array<Term>
Control that the number of actual arguments matches the relation’s arity.
-
#initialize(aName, anArity) ⇒ Specification
constructor
A new instance of Specification.
- #inspect ⇒ Object
-
#variadic? ⇒ Boolean
A relation is variadic when it accepts an arbitrary number of arguments.
Constructor Details
#initialize(aName, anArity) ⇒ Specification
Returns a new instance of Specification.
16 17 18 19 |
# File 'lib/mini_kraken/core/specification.rb', line 16 def initialize(aName, anArity) @name = aName @arity = anArity.is_a?(Integer) ? Arity.new(anArity, anArity) : anArity end |
Instance Attribute Details
#arity ⇒ Arity (readonly)
Returns arity = allowed number of arguments.
12 13 14 |
# File 'lib/mini_kraken/core/specification.rb', line 12 def arity @arity end |
#name ⇒ String (readonly)
Returns Name of the specification object.
9 10 11 |
# File 'lib/mini_kraken/core/specification.rb', line 9 def name @name end |
Instance Method Details
#check_arity(actuals) ⇒ Array<Term>
Control that the number of actual arguments matches the relation’s arity. Raise an exception if the check fails
37 38 39 40 41 42 43 44 45 |
# File 'lib/mini_kraken/core/specification.rb', line 37 def check_arity(actuals) unless arity.match?(actuals.size) msg1 = "Count of arguments (#{actuals.size})" msg2 = " is out of allowed range (#{arity.low}, #{arity.high})." raise StandardError, msg1 + msg2 end actuals end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/mini_kraken/core/specification.rb', line 28 def inspect name + "[#{arity.low}]" end |
#variadic? ⇒ Boolean
A relation is variadic when it accepts an arbitrary number of arguments. Most built-in relation takes a fixed number of arguments (= arity).
24 25 26 |
# File 'lib/mini_kraken/core/specification.rb', line 24 def variadic? arity.variadic? end |