Class: Stamina::Engine::Context
- Inherits:
-
Object
- Object
- Stamina::Engine::Context
- Includes:
- Enumerable
- Defined in:
- lib/stamina-core/stamina/engine/context.rb
Instance Attribute Summary collapse
-
#binding ⇒ Object
readonly
Returns the value of attribute binding.
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #each ⇒ Object
-
#initialize(vars, binding) ⇒ Context
constructor
A new instance of Context.
- #to_h ⇒ Object
- #to_s ⇒ Object
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
#binding ⇒ Object (readonly)
Returns the value of attribute binding.
6 7 8 |
# File 'lib/stamina-core/stamina/engine/context.rb', line 6 def binding @binding end |
#vars ⇒ Object (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 |
#each ⇒ Object
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_h ⇒ Object
23 24 25 |
# File 'lib/stamina-core/stamina/engine/context.rb', line 23 def to_h Hash[collect{|k,v| [k,v]}] end |
#to_s ⇒ Object
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 |