Module: Baptize::Plugins::Variables

Defined in:
lib/baptize/plugins/variables.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



27
28
29
30
31
32
33
# File 'lib/baptize/plugins/variables.rb', line 27

def method_missing(sym, *args, &block)
  if @variables && @variables[sym]
    fetch(sym)
  else
    super
  end
end

Instance Method Details

#fetch(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/baptize/plugins/variables.rb', line 12

def fetch(name)
  if @variables
    value = @variables[name.to_sym]
    if value.kind_of?(Proc)
      value.call
    else
      value
    end
  end
end

#respond_to?(sym, include_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/baptize/plugins/variables.rb', line 23

def respond_to?(sym, include_priv = false)
  super || (@variables && @variables[sym])
end

#set(name, value) ⇒ Object



7
8
9
10
# File 'lib/baptize/plugins/variables.rb', line 7

def set(name, value)
  @variables ||= {}
  @variables[name.to_sym] = value
end