Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/lrjew/linked_list.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#next ⇒ Object
Returns the value of attribute next.
-
#prev ⇒ Object
Returns the value of attribute prev.
Instance Method Summary collapse
-
#initialize(data, _next) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object (also: #to_s)
- #length ⇒ Object
- #push(data) ⇒ Object
Constructor Details
#initialize(data, _next) ⇒ Node
Returns a new instance of Node.
57 58 59 60 |
# File 'lib/lrjew/linked_list.rb', line 57 def initialize(data, _next) @data = data @next = _next end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
55 56 57 |
# File 'lib/lrjew/linked_list.rb', line 55 def data @data end |
#next ⇒ Object
Returns the value of attribute next.
54 55 56 |
# File 'lib/lrjew/linked_list.rb', line 54 def next @next end |
#prev ⇒ Object
Returns the value of attribute prev.
54 55 56 |
# File 'lib/lrjew/linked_list.rb', line 54 def prev @prev end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
76 77 78 79 80 |
# File 'lib/lrjew/linked_list.rb', line 76 def inspect prev_data = @prev && @prev.data || nil next_data = @next && @next.data || nil "#{prev_data.inspect} <- #{@data.inspect} -> #{next_data.inspect}" end |
#length ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/lrjew/linked_list.rb', line 62 def length if @data.nil? 0 else 1 + @next.length end end |