Hi! Loving the Ruby course so far but I had a quick question regarding the Amusement Park lesson.
In the Introduction to the exercise, the author states that methods which get values (i.e. query methods) should end with a question mark - see the suitcase example.
However, in the attendee.rb file, neither the height nor the pass_id getters follow this convention. I’m new to Ruby so unsure of the answer, but I hope it’s ok to ask here.
the author states that methods which get values (i.e. query methods) should end with a question mark
I did not see that same statement. I did see the statement that query methods should get a question mark (as a comment in code).
All methods return values in Ruby, so the statement would be overreaching in its effect. A query method in Ruby is a method that returns a boolean value, and often used in conjunction with a logic statement. In this case it SHOULD but is not required, and that question mark is a communication device, nothing special to the language.
As long as the definition of “query method” is defined as “a method that returns a truthy/falsey response to be used in conditional or logical statements” then it is true that it should be communicated by being named with a question mark.
The way that the method names are written at the moment, it is hard to see that indication that it should be used as a query (the pass id method) and one may think that perhaps the height method could be.
Ah I see the distinction! So getters which return a truthy/falsey response should end with a question mark, but getters which return other types should not. Thanks a lot @kotp!