Class: RubyCollections::LinkedList::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_collections/linked_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

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

#getNextObject



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_sObject



70
71
72
# File 'lib/ruby_collections/linked_list.rb', line 70

def to_s
  "#{data}"
end