Skip to content

HW1 Completed! (Panda, Tiger, and Eagle levels) #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jomarquez
Copy link

Looking forward to your feedback,
Thanks!
Joanna

def to_s
"#{@value}-#{suit}"
return abbr_suit + "#{value}"
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 "==".

cards = []
[:clubs, :diamonds, :spades, :hearts].each do |suit|
(2..10).each do |number|
cards << Card.new(suit, number) # << means add to the end of the array
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