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
53 54 55 56 |
# File 'lib/ruby_collections/linked_list.rb', line 53 def initialize(data, next_node) @data = data @next = next_node.object_id end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
51 52 53 |
# File 'lib/ruby_collections/linked_list.rb', line 51 def data @data end |
Instance Method Details
#getNext ⇒ Object
58 59 60 |
# File 'lib/ruby_collections/linked_list.rb', line 58 def getNext ObjectSpace._id2ref(@next) end |
#setNext(data) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/ruby_collections/linked_list.rb', line 62 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
70 71 72 |
# File 'lib/ruby_collections/linked_list.rb', line 70 def to_s "#{data}" end |