Class: Uinit::Type::Fn
Instance Attribute Summary collapse
-
#arity ⇒ Object
readonly
Returns the value of attribute arity.
Instance Method Summary collapse
- #check!(value, depth) ⇒ Object
-
#initialize(arity = -1)) ⇒ Fn
constructor
TODO: arguments.
- #inspect ⇒ Object
- #is?(value) ⇒ Boolean
Methods inherited from Base
#==, [], from, from?, #is!, #to_s, #trace!, #type_error!
Methods included from Operators
Constructor Details
#initialize(arity = -1)) ⇒ Fn
TODO: arguments
7 8 9 10 11 12 13 |
# File 'lib/uinit/type/fn.rb', line 7 def initialize(arity = -1) super() raise ArgumentError, 'arity must be an Integer' unless arity.is_a?(Integer) @arity = arity end |
Instance Attribute Details
#arity ⇒ Object (readonly)
Returns the value of attribute arity.
15 16 17 |
# File 'lib/uinit/type/fn.rb', line 15 def arity @arity end |
Instance Method Details
#check!(value, depth) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/uinit/type/fn.rb', line 25 def check!(value, depth) unless value.is_a?(Proc) || value.is_a?(Method) || value.is_a?(UnboundMethod) type_error!("#{value.inspect} must be an Proc a Method or a UnboundMethod", depth) end return value if arity == -1 || value.arity == -1 || value.arity == arity type_error!( "#{value.inspect} does not respect expected arity #{arity}, defined arity #{value.arity}", depth ) end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/uinit/type/fn.rb', line 38 def inspect "#{super}[arity = #{arity}]" end |
#is?(value) ⇒ Boolean
17 18 19 20 21 22 23 |
# File 'lib/uinit/type/fn.rb', line 17 def is?(value) return false unless value.is_a?(Proc) || value.is_a?(Method) || value.is_a?(UnboundMethod) return true if arity == -1 || value.arity == -1 value.arity == arity end |