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 Collections Build a Grocery List Program Build a Grocery List Program: Part 1

David Legault
David Legault
1,543 Points

Parentheses in create_list()

Hy guys,

I dont understand why we use parentheses in create_list(). Same thing with add_list_item().


2 Answers

The parenthesis does not need to be there since the method is defined with no arguments. In other languages, the empty parenthesis are necessary, but not in Ruby.

create_list() and add_list_item() are functions. The parenthesis are where functions accept parameters, and if a function has no parameters then the parenthesis are left empty.

They need to be there for the compiler to know they are functions. The compiler might get confused if you didn't put the parenthesis and it wouldn't know the difference between a function and a variable.