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 since in version <= 0.1.5 nodes were simple hashes
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
Instance Method Summary collapse
-
#==(other) ⇒ Object
compare two nodes.
-
#initialize(attrs = nil) ⇒ Node
constructor
A new instance of Node.
- #method_missing(method, *args, &block) ⇒ Object
- #update(h) ⇒ Object
Constructor Details
#initialize(attrs = nil) ⇒ Node
Returns a new instance of Node.
56 57 58 |
# File 'lib/graph.rb', line 56 def initialize(attrs=nil) @attrs = attrs || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/graph.rb', line 72 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 the value of attribute attrs.
54 55 56 |
# File 'lib/graph.rb', line 54 def attrs @attrs end |
Instance Method Details
#==(other) ⇒ Object
compare two nodes
62 63 64 65 66 |
# File 'lib/graph.rb', line 62 def ==(other) return false if !other.is_a?(Node) @attrs == other.attrs end |
#update(h) ⇒ Object
68 69 70 |
# File 'lib/graph.rb', line 68 def update(h) Node.new super(h) end |