Class: Lab42::Console::Function
- Inherits:
-
Object
- Object
- Lab42::Console::Function
- Defined in:
- lib/lab42/console/function.rb
Constant Summary collapse
- Error =
Class.new RuntimeError
Instance Attribute Summary collapse
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
Instance Attribute Details
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
6 7 8 |
# File 'lib/lab42/console/function.rb', line 6 def functions @functions end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
6 7 8 |
# File 'lib/lab42/console/function.rb', line 6 def sources @sources end |
Instance Method Details
#add(*args, &blk) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/lab42/console/function.rb', line 8 def add(*args, &blk) if args.empty? _add_blk(blk) else raise Error, "must not provide literal and block behaviour at the same time" if blk _add_args(args) end self end |
#call(element) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/lab42/console/function.rb', line 18 def call(element) functions .inject(element) do |acc, fn| fn.(acc) end end |
#to_proc ⇒ Object
25 26 27 |
# File 'lib/lab42/console/function.rb', line 25 def to_proc -> x { call(x) } end |