Class: DslAccessor::AutoDeclare::DefineInstanceMethod

Inherits:
BlankSlate
  • Object
show all
Defined in:
lib/dsl_accessor/auto_declare.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, &block) ⇒ DefineInstanceMethod

Returns a new instance of DefineInstanceMethod.



21
22
23
24
# File 'lib/dsl_accessor/auto_declare.rb', line 21

def initialize(klass, &block)
  @klass = klass
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



27
28
29
30
31
32
33
# File 'lib/dsl_accessor/auto_declare.rb', line 27

def method_missing(name, *args, &block)
  if args.empty? and block
    @klass.class_eval{ define_method(name, &block) }
  else
    raise NameError, "undefined local variable or method `#{name}'"
  end
end