Class: MTK::Lang::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/mtk/lang/variable.rb

Overview

A placeholder element for a variable value, for use within a Patterns::Pattern such as a Patterns::ForEach pattern. Will be evaluated to an actual value by the Pattern or Sequencer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = nil) ⇒ Variable

Returns a new instance of Variable.



12
13
14
15
16
# File 'lib/mtk/lang/variable.rb', line 12

def initialize name, value=nil
  @name = name
  @value = value
  @implicit = !!(name =~ /^\$+$/)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/mtk/lang/variable.rb', line 8

def name
  @name
end

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/mtk/lang/variable.rb', line 10

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
# File 'lib/mtk/lang/variable.rb', line 23

def == other
  other.is_a? self.class and other.name == self.name
end

#implicit?Boolean

Returns true when this variable has no specific value and references the implicit variable stack (such as in a Patterns::ForEach).

Returns:

  • (Boolean)

    true when this variable has no specific value and references the implicit variable stack (such as in a Patterns::ForEach)



19
20
21
# File 'lib/mtk/lang/variable.rb', line 19

def implicit?
  @implicit
end

#to_sObject



27
28
29
# File 'lib/mtk/lang/variable.rb', line 27

def to_s
  "#{self.class}<#{name}#{'='+value.to_s if value}>"
end