Class: Blaml::MetaNode

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

Overview

Simple wrapper class to assign metadata to object instances.

Direct Known Subclasses

MetaArray, MetaHash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, meta = nil) ⇒ MetaNode

Create a new MetaNode with the value to wrap and optional metadata.



19
20
21
22
# File 'lib/blaml/meta.rb', line 19

def initialize value, meta=nil
  @value = value
  @meta  = meta
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Sends non-defined methods to the value attribute



54
55
56
# File 'lib/blaml/meta.rb', line 54

def method_missing name, *args, &block
  @value.send name, *args, &block
end

Instance Attribute Details

#metaObject

Accessor for the meta attribute. Overridden in MetaArray and MetaHash classes.



41
42
43
# File 'lib/blaml/meta.rb', line 41

def meta
  @meta
end

#valueObject (readonly)

The object to assign metadata to.



11
12
13
# File 'lib/blaml/meta.rb', line 11

def value
  @value
end

Instance Method Details

#==(obj) ⇒ Object

Checks for equality against the value attribute.



28
29
30
31
32
33
34
# File 'lib/blaml/meta.rb', line 28

def == obj
  case obj
  when MetaNode then obj.value == @value
  else
    @value == obj
  end
end

#to_valueObject

Accessor for the value attribute. Overridden in MetaArray and MetaHash classes.



63
64
65
# File 'lib/blaml/meta.rb', line 63

def to_value
  @value
end

#to_yamlObject

Output @value yaml string.



71
72
73
# File 'lib/blaml/meta.rb', line 71

def to_yaml
  self.to_value.to_yaml
end