Class: Stamina::Engine::Context

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/stamina-core/stamina/engine/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vars, binding) ⇒ Context

Returns a new instance of Context.



8
9
10
11
# File 'lib/stamina-core/stamina/engine/context.rb', line 8

def initialize(vars, binding)
  @vars = vars.collect{|v| v.to_sym}
  @binding = binding
end

Instance Attribute Details

#bindingObject (readonly)

Returns the value of attribute binding.



6
7
8
# File 'lib/stamina-core/stamina/engine/context.rb', line 6

def binding
  @binding
end

#varsObject (readonly)

Returns the value of attribute vars.



6
7
8
# File 'lib/stamina-core/stamina/engine/context.rb', line 6

def vars
  @vars
end

Instance Method Details

#[](name) ⇒ Object



19
20
21
# File 'lib/stamina-core/stamina/engine/context.rb', line 19

def [](name)
  binding.eval(name.to_s)
end

#eachObject



13
14
15
16
17
# File 'lib/stamina-core/stamina/engine/context.rb', line 13

def each
  vars.each do |key|
    yield(key, self[key])
  end
end

#to_hObject



23
24
25
# File 'lib/stamina-core/stamina/engine/context.rb', line 23

def to_h
  Hash[collect{|k,v| [k,v]}]
end

#to_sObject



27
28
29
30
31
# File 'lib/stamina-core/stamina/engine/context.rb', line 27

def to_s
  collect{|k,v|
    "#{k}: #{v}"
  }.join("\n")
end