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

Nate Eizenhoefer
Nate Eizenhoefer
5,312 Points

transaction vs transactions and does it being plural matter?

here is a @transactions = [] then when you loop it a loop you don't put transactions you put

@transactions.each do |transaction|

Now... how does Ruby understand transaction vs transactions? as I never typed transaction as a "method".

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Nate,

In the example you provided, transaction (singular) isn't a method. It is a temporary variable that will store the value of each iteration through the transactions (plural) array. Every iteration will store the new value in the temporary variable to be used in which ever way you code. The next iteration will then remove the first value from the temporary variable and store the new value... and so on until the loop has completed going through the array.

transaction (singular) could have been named anything. I've seen some coders use single letters (eg t because that's the first letter of the array name). However, the convention is to name the temporary variable the singular version of the plural name that the array has.

I hope this helps, but it also wouldn't hurt to take a quick review of for loops.

Keep Coding! :) :dizzy:

Nate Eizenhoefer
Nate Eizenhoefer
5,312 Points

hey Jason, thanks for the response. this makes sense.