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 Legault
1,543 PointsParentheses in create_list()
Hy guys,
I dont understand why we use parentheses in create_list(). Same thing with add_list_item().
Thanks
2 Answers
bashburn
7,611 PointsThe 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.
James Attree
7,906 Pointscreate_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.
Terrence Beckham
Courses Plus Student 879 PointsIn Ruby, the parenthesis are optional.