Class: Rtml::HighLevel::Subroutine
- Inherits:
-
Object
- Object
- Rtml::HighLevel::Subroutine
- Defined in:
- lib/rtml/high_level/subroutine.rb
Instance Method Summary collapse
- #call(context, args) ⇒ Object
-
#initialize(name, parent, options = {}, &blk) ⇒ Subroutine
constructor
A new instance of Subroutine.
Constructor Details
#initialize(name, parent, options = {}, &blk) ⇒ Subroutine
Returns a new instance of Subroutine.
2 3 4 5 6 |
# File 'lib/rtml/high_level/subroutine.rb', line 2 def initialize(name, parent, = {}, &blk) @block = blk @name = name @parent = parent end |
Instance Method Details
#call(context, args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rtml/high_level/subroutine.rb', line 8 def call(context, args) method_name = @name block = @block (class << context; self; end).instance_eval do define_method method_name, &block new_method = instance_method(method_name) define_method method_name do |arguments| new_method.bind(self).call(arguments) end end context.send(method_name, args) end |