Class: ComposableProc
- Defined in:
- lib/lab419/core/extensions/composable_proc.rb
Instance Attribute Summary collapse
-
#my_lambda ⇒ Object
readonly
Returns the value of attribute my_lambda.
Class Method Summary collapse
Instance Method Summary collapse
- #and(lmbda = nil, &block) ⇒ Object (also: #+)
- #arity ⇒ Object
- #call(*args, &blk) ⇒ Object (also: #[])
- #to_proc ⇒ Object
Instance Attribute Details
#my_lambda ⇒ Object (readonly)
Returns the value of attribute my_lambda.
3 4 5 |
# File 'lib/lab419/core/extensions/composable_proc.rb', line 3 def my_lambda @my_lambda end |
Class Method Details
Instance Method Details
#and(lmbda = nil, &block) ⇒ Object Also known as: +
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lab419/core/extensions/composable_proc.rb', line 5 def and lmbda=nil, &block raise ArgumentError, "either use a lambda or a block" if !!block == !!lmbda self.class.new do | *args, &blk | nxt = lmbda || block results = my_lambda.( *args, &blk ) if Array === results if nxt.arity < 0 || nxt.arity == results.size nxt.( *results ) elsif nxt.arity.zero? nxt.() else nxt.( results ) end else nxt.( results ) end end end |
#arity ⇒ Object
25 |
# File 'lib/lab419/core/extensions/composable_proc.rb', line 25 def arity; my_lambda.arity end |
#call(*args, &blk) ⇒ Object Also known as: []
27 28 29 |
# File 'lib/lab419/core/extensions/composable_proc.rb', line 27 def call *args, &blk my_lambda.call( *args, &blk ) end |
#to_proc ⇒ Object
32 |
# File 'lib/lab419/core/extensions/composable_proc.rb', line 32 def to_proc; my_lambda.to_proc end |