Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Foundations Ruby Core Symbols

gerald blady
gerald blady
9,052 Points

.push command

Ran the code as follows.

ruby 1-symbols.rb

1-symbols.rb:9:in deposit': undefined methodpush' for nil:NilClass (NoMethodError)

not sure why it's kicking back that error, code is same as Jasons.

class BankAccount
    def initialize(name)
        @name = name 
        @transaction = []
    end

    def deposit(amount, options={})
        options[:memo] ||= 'Regular deposit.'
        @transactions.push({:amount => amount, :memo => options[:memo]})
    end
end

bank_account = BankAccount.new("jerry")
bank_account.deposit(100)
bank_account.deposit(100, {:memo => "This was a gift."})

puts bank_account.inspect

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Make sure your @transaction/@transactions instance variable is either singular or plural in ALL lines where it appears. Otherwise these are two different variables.

gerald blady
gerald blady
9,052 Points

Thank you for the swift reply. Knew it had to be something simple which it was.