I'm trying to write a method that will cause a rspec test like this to pass:
it "starts the thing and move on" do
class.method_1("Name One")
class.method_1("Name Two")
expect(class.method_2).to eq "Some string Name One"
expect(class.method_3).to eq ["Name Two"]
end
method_1 just adds a name to an array, and method_3 returns the array (defined in initialize method):
def method_1(name)
@array << name
end
def method_3
@array
end
I figured it would be pretty simple to interpolate @array[0] into the string and use @array.delete_at(0) to modify the array. Like so:
def method_2
p "Some string #{@array[0]}"
@array.delete_at(0)
end
But that method returns "Name One" instead of the string. If I comment out the delete code, the string returns properly but my array hasn't been modified. I've been in Ruby docs for a long time but #shift has the same issue about returning the removed item.
I'm almost certain I've over complicated this -- what am I missing?