Class: Fluid::Var

Inherits:
Object
  • Object
show all
Defined in:
lib/fluid.rb

Overview

There are different kinds of variables. They use the environment differently.

Direct Known Subclasses

FluidVar, GlobalVar

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

:nodoc:



34
35
36
# File 'lib/fluid.rb', line 34

def name
  @name
end

#original_nameObject (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

Returns:

  • (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_bindingObject



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