Sha256: 4dc1cfece30e70eee7c46e82be8ff98c19e17c5a8d4f6d463642c543d181b1c6

Contents?: true

Size: 518 Bytes

Versions: 4

Compression:

Stored size: 518 Bytes

Contents

class Rtml::HighLevel::Subroutine
  def initialize(name, parent, options = {}, &blk)
    @block = blk
    @name = name
    @parent = parent
  end

  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rtml-2.0.3 lib/rtml/high_level/subroutine.rb
rtml-2.0.2 lib/rtml/high_level/subroutine.rb
rtml-2.0.1 lib/rtml/high_level/subroutine.rb
rtml-2.0.0.alpha.1 lib/rtml/high_level/subroutine.rb