Class: LinkedList::DoublyNode

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, backward = nil, forward = nil) ⇒ DoublyNode

Returns a new instance of DoublyNode.



21
22
23
24
25
26
# File 'lib/linked_list_sourav.rb', line 21

def initialize(data, backward=nil, forward=nil)
  @data = data
  @backward = backward
  @forward = forward
  self
end

Instance Attribute Details

#backwardObject

Returns the value of attribute backward.



20
21
22
# File 'lib/linked_list_sourav.rb', line 20

def backward
  @backward
end

#dataObject

Returns the value of attribute data.



20
21
22
# File 'lib/linked_list_sourav.rb', line 20

def data
  @data
end

#forwardObject

Returns the value of attribute forward.



20
21
22
# File 'lib/linked_list_sourav.rb', line 20

def forward
  @forward
end

Instance Method Details

#to_sObject



28
29
30
31
32
33
# File 'lib/linked_list_sourav.rb', line 28

def to_s
  string = "Data: #{self.data} "
  string << "Points to: #{self.forward.data}" if self.forward
  string << " Pointed by: #{self.backward.data}" if self.backward
  string
end