Class: Fluid::Var
- Inherits:
-
Object
- Object
- Fluid::Var
- Defined in:
- lib/fluid.rb
Overview
There are different kinds of variables. They use the environment differently.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
:nodoc:.
-
#original_name ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.build(original_name, environment, value_destructor = nil) ⇒ Object
Factory method that returns subclasses of Var.
- .global?(string_or_symbol) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(original_name, environment, value_destructor) ⇒ Var
constructor
A new instance of Var.
- #pop_binding ⇒ Object
-
#push_binding(value) ⇒ Object
These two methods are the ones used to manipulate the environment.
Constructor Details
#initialize(original_name, environment, value_destructor) ⇒ Var
Returns a new instance of Var.
47 48 49 50 51 52 |
# File 'lib/fluid.rb', line 47 def initialize(original_name, environment, value_destructor) @original_name = original_name @name = Var.ensure_symbol(original_name) @environment = environment @value_destructor = value_destructor end |
Instance Attribute Details
#name ⇒ Object (readonly)
:nodoc:
34 35 36 |
# File 'lib/fluid.rb', line 34 def name @name end |
#original_name ⇒ Object (readonly)
:nodoc:
34 35 36 |
# File 'lib/fluid.rb', line 34 def original_name @original_name end |
Class Method Details
.build(original_name, environment, value_destructor = nil) ⇒ Object
Factory method that returns subclasses of Var.
38 39 40 41 |
# File 'lib/fluid.rb', line 38 def Var.build(original_name, environment, value_destructor=nil) klass = (global?(original_name)) ? GlobalVar : FluidVar klass.build(original_name, environment, value_destructor) end |
.global?(string_or_symbol) ⇒ Boolean
43 44 45 |
# File 'lib/fluid.rb', line 43 def Var.global?(string_or_symbol) ?$ == string_or_symbol.to_s[0] end |
Instance Method Details
#pop_binding ⇒ Object
61 62 63 64 65 |
# File 'lib/fluid.rb', line 61 def pop_binding previous = @environment.pop_binding(name) apply_value_destructor(previous) if @value_destructor destroy if @environment.unbound?(name) end |
#push_binding(value) ⇒ Object
These two methods are the ones used to manipulate the environment. Note subclasses.
56 57 58 59 |
# File 'lib/fluid.rb', line 56 def push_binding(value) create unless @environment.has?(name) @environment.push_binding(name, value) end |