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 trialDavid Greenstein
6,734 PointsWhy doesnt writing a hash like this work
This should be the exact same thing as what is occurring in the video
def add_transaction(description, amount)
@transactions.push({"description" => description, "amount" => amount})
end
class BankAccount
attr_reader :name
def initialize(name)
@name = name
@transactions = []
end
def add_transaction(description, amount)
@transactions.push({"description" => description, "amount" => amount})
end
end
1 Answer
Michael Hulet
47,913 PointsPay attention to what they challenge is asking you to do here. It wants you to use symbols for the keys, but you're using strings. Otherwise, your code should work
David Greenstein
6,734 PointsDavid Greenstein
6,734 PointsWhy dont you need the curly brackets then?
Michael Hulet
47,913 PointsMichael Hulet
47,913 PointsIn Ruby, when you're passing a hash literal into a method, you don't need to write the curly brackets around a hash literal, because Ruby can tell from your use of the
=>
operator or symbols with the colon on the right side that you mean to have a hash literal there. It's just one of the cool syntactical sugar features of the language