Class: RubyCollections::LinkedList::Node
- Inherits:
-
Object
- Object
- RubyCollections::LinkedList::Node
- Defined in:
- lib/ruby_collections/linked_list.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #getNext ⇒ Object
-
#initialize(data, next_node) ⇒ Node
constructor
A new instance of Node.
- #setNext(data) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data, next_node) ⇒ Node
56 57 58 59 |
# File 'lib/ruby_collections/linked_list.rb', line 56 def initialize(data, next_node) @data = data @next = next_node.object_id end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
54 55 56 |
# File 'lib/ruby_collections/linked_list.rb', line 54 def data @data end |
Instance Method Details
#getNext ⇒ Object
61 62 63 |
# File 'lib/ruby_collections/linked_list.rb', line 61 def getNext ObjectSpace._id2ref(@next) end |
#setNext(data) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/ruby_collections/linked_list.rb', line 65 def setNext(data) node = Node.new(data, nil) next_node_id = instance_variable_get(:@next) @next = node.object_id node.instance_variable_set(:@next, next_node_id) return node end |
#to_s ⇒ Object
73 74 75 |
# File 'lib/ruby_collections/linked_list.rb', line 73 def to_s "#{data}" end |