Skip to content

Conversation

jomarquez
Copy link

Looking forward to your feedback,
Thanks!
Joanna

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only like to use return for early returns. Not a huge deal, obviously, but I think it s a decent enough convention

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is an early return? is it when you do
return :something if something == 2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use the .eql? method is my recommendation.

@jwo
Copy link
Member

jwo commented Dec 1, 2012

This looks really good... I was curious to know why you went with the ".eql?" method call over the "==".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: "<<" is referred to as the "shovel" operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants