Class: Graph::Node
- Inherits:
-
Object
- Object
- Graph::Node
- Defined in:
- lib/graph.rb
Overview
A node. This class is just a wrapper around a hash of attributes. Before 0.1.6, nodes were simple hashs
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Node’s attributes.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
compare two nodes.
-
#initialize(attrs = nil) ⇒ Node
constructor
Create a new Node.
- #method_missing(method, *args, &block) ⇒ Object
-
#update(h) ⇒ Node
Update the current node, like the Hash#update method.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/graph.rb', line 79 def method_missing(method, *args, &block) return @attrs[method.to_sym] if @attrs.has_key? method.to_sym return @attrs[method.to_s] if @attrs.has_key? method.to_s @attrs.send(method, *args, &block) end |
Instance Attribute Details
#attrs ⇒ Object
Returns Node’s attributes.
55 56 57 |
# File 'lib/graph.rb', line 55 def attrs @attrs end |
Instance Method Details
#==(other) ⇒ Boolean
compare two nodes
66 67 68 69 70 |
# File 'lib/graph.rb', line 66 def ==(other) return false if !other.is_a?(Node) @attrs == other.attrs end |