-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: master
Are you sure you want to change the base?
Conversation
def to_s | ||
"#{@value}-#{suit}" | ||
return abbr_suit + "#{value}" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
Looking forward to your feedback,
Thanks!
Joanna