Class: WAG::Label

Inherits:
Object
  • Object
show all
Includes:
Encodable
Defined in:
lib/wag/label.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Encodable

#to_wasm, #to_wat

Constructor Details

#initialize(value) ⇒ Label

Returns a new instance of Label.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/wag/label.rb', line 9

def initialize(value)
  if value.is_a?(Integer)
    @value = value.to_i
  else
    value = value.to_s
    @value = if value.start_with?('$')
               value.to_sym
             else
               "$#{value}".to_sym
             end
  end
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/wag/label.rb', line 7

def value
  @value
end

Class Method Details

.from(value) ⇒ Object



26
27
28
29
30
# File 'lib/wag/label.rb', line 26

def self.from(value)
  return value if value.is_a?(WAG::Label)

  WAG::Label.new(value)
end

Instance Method Details

#to_sexprObject



22
23
24
# File 'lib/wag/label.rb', line 22

def to_sexpr
  value
end