Class: Lab42::Behavior::UnboundBehavior
- Includes:
- Lab42::Behavior
- Defined in:
- lib/lab42/core/behavior/unbound_behavior.rb
Overview
Thank youn my dear Proxy, for sending me all the information I, the clever guy, who is having all the fun, will make best use of it by being an extremly, yes I said extremly clever callable object representing the methods or instance methods represented by the calls to ‘Object#fn` or `Module#fm`. Did I tell you yet? It is sooooo out not be functional…
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
-
#_(*a, &b) ⇒ Object
Rebinding: We still apply our LIFO policy! So much for the proverbial “The early bird catches the worm”? Anyway, what would I do with a worm??? (Mescal maybe?).
-
#arity ⇒ Object
Increment method’s arity by one as we need to bind the first argument to the method.
- #call(*a, &b) ⇒ Object
- #to_proc ⇒ Object
Methods included from Composition
Methods included from Negation
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
13 14 15 |
# File 'lib/lab42/core/behavior/unbound_behavior.rb', line 13 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
13 14 15 |
# File 'lib/lab42/core/behavior/unbound_behavior.rb', line 13 def block @block end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
13 14 15 |
# File 'lib/lab42/core/behavior/unbound_behavior.rb', line 13 def method @method end |
Instance Method Details
#_(*a, &b) ⇒ Object
Rebinding: We still apply our LIFO policy! So much for the proverbial “The early bird catches the worm”? Anyway, what would I do with a worm??? (Mescal maybe?)
39 40 41 |
# File 'lib/lab42/core/behavior/unbound_behavior.rb', line 39 def _ *a, &b self.class.new @klass, method, *(a + args), &(b||block) end |
#arity ⇒ Object
Increment method’s arity by one as we need to bind the first argument to the method
17 18 19 |
# File 'lib/lab42/core/behavior/unbound_behavior.rb', line 17 def arity method.arity.succ end |
#call(*a, &b) ⇒ Object
21 22 23 24 25 |
# File 'lib/lab42/core/behavior/unbound_behavior.rb', line 21 def call *a, &b available_args = a + args m = method.bind available_args.first m.( *available_args.drop(1), &(b||block) ) end |
#to_proc ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/lab42/core/behavior/unbound_behavior.rb', line 27 def to_proc proc do |*a, &b| available_args = a + args method.bind( available_args.first ) .( *available_args.drop(1), &(b||block) ) end end |