Class: Kase::Switcher::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/kase/switcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(switcher, context) ⇒ DSL

Returns a new instance of DSL.



45
46
47
48
# File 'lib/kase/switcher.rb', line 45

def initialize(switcher, context)
  @__switcher = switcher
  @__context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



68
69
70
# File 'lib/kase/switcher.rb', line 68

def method_missing(method, *args, &block)
  @__context.send(method, *args, &block)
end

Instance Method Details

#__call(&block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kase/switcher.rb', line 50

def __call(&block)
  @__context.instance_variables.each do |name|
    next if name.to_s =~ /^@__/
    instance_variable_set(name, @__context.instance_variable_get(name))
  end

  instance_eval(&block)

  instance_variables.each do |name|
    next if name.to_s =~ /^@__/
    @__context.instance_variable_set(name, instance_variable_get(name))
  end
end

#on(*args, &block) ⇒ Object



64
65
66
# File 'lib/kase/switcher.rb', line 64

def on(*args, &block)
  @__switcher.on(*args, &block)
end