HW1 Completed! (Panda, Tiger, and Eagle levels)#18
HW1 Completed! (Panda, Tiger, and Eagle levels)#18jomarquez wants to merge 1 commit intoRubyoffRails:masterfrom
Conversation
There was a problem hiding this comment.
I only like to use return for early returns. Not a huge deal, obviously, but I think it s a decent enough convention
There was a problem hiding this comment.
what is an early return? is it when you do
return :something if something == 2
There was a problem hiding this comment.
regarding using the ".eql?" method call over the "=="...I am not sure why I did that. is there a rule of when we should use one over the other one?
thanks for your feedback.
-j
There was a problem hiding this comment.
This is an example of an early return:
def average(objects)
return 0 if objects.length == 0
objects.inject(:+) / objects.length
end
The return causes an early exit from the method. In Ruby, you do not need to add a "return" at the end of a method. It's implicity and you don't want to break this convention.
There was a problem hiding this comment.
Don't use the .eql? method is my recommendation.
|
This looks really good... I was curious to know why you went with the ".eql?" method call over the "==". |
There was a problem hiding this comment.
FYI: "<<" is referred to as the "shovel" operator.
Looking forward to your feedback,
Thanks!
Joanna