Ruby newb here. I am trying to create a class that has a array as its attribute and I want to add elements to a method of the class. I don't know the elements of the array beforehand so I can't do something like this
So far I have tried the following but it doesn't work
class Test
attr_accessor :test_string
def initialize
@test_string = []
end
def test_if_array
test_string << "Foobar" #doesn't work
test_string.push("Barbaz") #doesn't work
@test_string.push("Bla") #doesn't work
self.test_string << "foo" #doesn't work
self.test_string.push("bar") #doesn't work
end
end
tester = Test.new
p tester.test_string
Can anyone tell me how to push strings in the array programatically?