Class: Blaml::MetaNode
- Inherits:
-
Object
- Object
- Blaml::MetaNode
- Defined in:
- lib/blaml/meta.rb
Overview
Simple wrapper class to assign metadata to object instances.
Instance Attribute Summary collapse
-
#meta ⇒ Object
Accessor for the meta attribute.
-
#value ⇒ Object
readonly
The object to assign metadata to.
Instance Method Summary collapse
-
#==(obj) ⇒ Object
Checks for equality against the value attribute.
-
#initialize(value, meta = nil) ⇒ MetaNode
constructor
Create a new MetaNode with the value to wrap and optional metadata.
-
#method_missing(name, *args, &block) ⇒ Object
Sends non-defined methods to the value attribute.
-
#to_value ⇒ Object
Accessor for the value attribute.
-
#to_yaml ⇒ Object
Output @value yaml string.
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, =nil @value = value @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
#meta ⇒ Object
Accessor for the meta attribute. Overridden in MetaArray and MetaHash classes.
41 42 43 |
# File 'lib/blaml/meta.rb', line 41 def @meta end |
#value ⇒ Object (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_value ⇒ Object
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_yaml ⇒ Object
Output @value yaml string.
71 72 73 |
# File 'lib/blaml/meta.rb', line 71 def to_yaml self.to_value.to_yaml end |