Class: LinkedList::Node
- Inherits:
-
Object
- Object
- LinkedList::Node
- Defined in:
- lib/linked_list/node.rb
Overview
Implements a single node of the linked list.
Instance Attribute Summary collapse
-
#cdr ⇒ Object
Returns the value of attribute cdr.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two nodes are equal if their values are equal and their cdr’s are equal too.
-
#initialize(value, cdr) ⇒ Node
constructor
A new instance of Node.
-
#inspect ⇒ Object
Returns a nice-looking string.
Constructor Details
#initialize(value, cdr) ⇒ Node
Returns a new instance of Node.
6 7 8 |
# File 'lib/linked_list/node.rb', line 6 def initialize(value, cdr) @cdr, @value = cdr, value end |
Instance Attribute Details
#cdr ⇒ Object
Returns the value of attribute cdr.
4 5 6 |
# File 'lib/linked_list/node.rb', line 4 def cdr @cdr end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/linked_list/node.rb', line 4 def value @value end |
Instance Method Details
#==(other) ⇒ Object
Two nodes are equal if their values are equal and their cdr’s are equal too.
11 12 13 |
# File 'lib/linked_list/node.rb', line 11 def ==(other) cdr == other.cdr && value == other.value end |
#inspect ⇒ Object
Returns a nice-looking string.
node = LinkedList::Node.new("a", nil)
node.inspect
#=> ("a" nil)
19 20 21 |
# File 'lib/linked_list/node.rb', line 19 def inspect "(#{value.inspect} #{cdr.inspect})" end |