Class: Fluid::GlobalVar
Overview
GlobalVars are the subclass that handles binding and unbinding of Ruby globals.
Instance Attribute Summary
Attributes inherited from Var
Class Method Summary collapse
Instance Method Summary collapse
- #assert_acceptable_name ⇒ Object
-
#create ⇒ Object
The original value of the global is, in effect, an outermost binding, one not created with Fluid.let.
- #pop_binding ⇒ Object
-
#push_binding(value) ⇒ Object
The environment really just holds values for unbinding.
- #set_global ⇒ Object
Methods inherited from Var
Constructor Details
This class inherits a constructor from Fluid::Var
Class Method Details
.build(original_name, environment, value_destructor) ⇒ Object
:nodoc:
138 139 140 |
# File 'lib/fluid.rb', line 138 def GlobalVar.build(original_name, environment, value_destructor) new(original_name, environment, value_destructor) end |
Instance Method Details
#assert_acceptable_name ⇒ Object
170 171 172 173 174 175 |
# File 'lib/fluid.rb', line 170 def assert_acceptable_name if [:$!, :$stdin, :$stdout, :$stderr].include?(name) raise NameError, "'#{name}' is not allowed in Fluid.let. It's too iffy to get it right." end end |
#create ⇒ Object
The original value of the global is, in effect, an outermost binding, one not created with Fluid.let. A binding has to be made here so that unbinding works on exit from the Fluid.let block.
145 146 147 148 |
# File 'lib/fluid.rb', line 145 def create super push_binding(instance_eval("#{name.to_s}")) end |
#pop_binding ⇒ Object
159 160 161 162 |
# File 'lib/fluid.rb', line 159 def pop_binding super set_global end |
#push_binding(value) ⇒ Object
The environment really just holds values for unbinding. Access to the newly-bound variable within the Fluid.let block is through the global itself. So it needs to be set and reset by these methods.
154 155 156 157 |
# File 'lib/fluid.rb', line 154 def push_binding(value) super set_global end |
#set_global ⇒ Object
164 165 166 167 168 |
# File 'lib/fluid.rb', line 164 def set_global evalme = "#{name.to_s} = @environment.get(#{name.inspect})" # puts evalme instance_eval evalme end |