Class: Crisp::Env
- Inherits:
-
Object
- Object
- Crisp::Env
- Defined in:
- lib/crisp/env.rb
Overview
The Crisp environment is basically a key/value store. The value for each key is immutable, so you can only store one time for each key
Instance Attribute Summary collapse
-
#global_loop_data ⇒ Object
Returns the value of attribute global_loop_data.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value for the given key.
-
#[]=(key, val) ⇒ Object
Store the key/value pair.
-
#alias(to, from) ⇒ Object
Store alias.
-
#has_key?(key) ⇒ Boolean
Returns boolean for existence of given key in the environment.
-
#initialize ⇒ Env
constructor
create a new internal hash.
Constructor Details
#initialize ⇒ Env
create a new internal hash
8 9 10 |
# File 'lib/crisp/env.rb', line 8 def initialize @map = {} end |
Instance Attribute Details
#global_loop_data ⇒ Object
Returns the value of attribute global_loop_data.
5 6 7 |
# File 'lib/crisp/env.rb', line 5 def global_loop_data @global_loop_data end |
Instance Method Details
#[](key) ⇒ Object
Returns the value for the given key.
18 19 20 21 22 23 24 25 26 |
# File 'lib/crisp/env.rb', line 18 def [](key) result = @map[key.to_sym] if result.class == Hash and result[:alias_to] self[result[:alias_to]] else result end end |
#[]=(key, val) ⇒ Object
Store the key/value pair. It is only possible to store a value for a key once, otherwise a error will be raised.
30 31 32 33 34 |
# File 'lib/crisp/env.rb', line 30 def []=(key, val) key = key.to_sym raise EnvironmentError, "#{key} already binded" if @map.has_key?(key) @map[key] = val end |
#alias(to, from) ⇒ Object
Store alias
37 38 39 |
# File 'lib/crisp/env.rb', line 37 def alias(to, from) self[to] = {:alias_to => from} end |
#has_key?(key) ⇒ Boolean
Returns boolean for existence of given key in the environment.
13 14 15 |
# File 'lib/crisp/env.rb', line 13 def has_key?(key) @map.has_key?(key.to_sym) end |