Class: Kolom::MetaProgramming::DSLContext
- Inherits:
-
Object
- Object
- Kolom::MetaProgramming::DSLContext
- Defined in:
- lib/kolom/metaprogramming.rb
Overview
DSL support
Instance Method Summary collapse
- #evaluate(&block) ⇒ Object
-
#initialize ⇒ DSLContext
constructor
A new instance of DSLContext.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ DSLContext
Returns a new instance of DSLContext.
32 33 34 |
# File 'lib/kolom/metaprogramming.rb', line 32 def initialize @data = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/kolom/metaprogramming.rb', line 36 def method_missing(method_name, *args, &block) if block_given? @data[method_name] = instance_exec(&block) elsif args.size > 0 @data[method_name] = args.size == 1 ? args.first : args else @data[method_name] end end |
Instance Method Details
#evaluate(&block) ⇒ Object
50 51 52 53 |
# File 'lib/kolom/metaprogramming.rb', line 50 def evaluate(&block) instance_eval(&block) @data end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
46 47 48 |
# File 'lib/kolom/metaprogramming.rb', line 46 def respond_to_missing?(method_name, include_private = false) true end |