Skip to content

Commit

Permalink
Add size method
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdabbs committed Nov 23, 2015
1 parent b54b46c commit d5529b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 18 additions & 6 deletions rearray.rb
@@ -1,25 +1,37 @@
class Node
def initialize value
@value = value
end
attr_accessor :next, :value

def value
@value
def initialize value
self.value = value
end
end

class Rearray
def initialize
@start = nil
@last = nil
end

def push thing
node = Node.new thing
if @start
i_dont_know
@last.next = node
@last = node
else
@start = node
@last = node
end
end

def size
return 0 unless @start
curr = @start
count = 1
while curr != @last
curr = curr.next
count += 1
end
count
end

def first
Expand Down
1 change: 1 addition & 0 deletions spec/rearray_spec.rb
@@ -1,4 +1,5 @@
require "spec_helper"
require "pry"
require_relative "../rearray"

describe Rearray do
Expand Down

0 comments on commit d5529b3

Please sign in to comment.