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

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Looking forward to your feedback,
Thanks!
Joanna

@jwo jwo commented on the diff Dec 1, 2012

blackjack.rb
def to_s
- "#{@value}-#{suit}"
+ return abbr_suit + "#{value}"
@jwo

jwo Dec 1, 2012

Owner

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

@jomarquez

jomarquez Dec 1, 2012

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

@jomarquez

jomarquez Dec 1, 2012

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

@jwo

jwo Dec 2, 2012

Owner

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.

@jwo

jwo Dec 2, 2012

Owner

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

Owner

jwo commented Dec 1, 2012

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

@jwo jwo commented on the diff Dec 1, 2012

blackjack.rb
@@ -28,16 +43,18 @@ def initialize
end
def self.build_cards
- cards = []
- [:clubs, :diamonds, :spades, :hearts].each do |suit|
- (2..10).each do |number|
- cards << Card.new(suit, number)
- end
- ["J", "Q", "K", "A"].each do |facecard|
- cards << Card.new(suit, facecard)
- end
- end
- cards.shuffle
+ 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
@jwo

jwo Dec 1, 2012

Owner

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

@jwo jwo commented on the diff Dec 1, 2012

blackjack.rb
return :dealer if player_value > 21
return :player if dealer_value > 21
- if player_value == dealer_value
- :push
- elsif player_value > dealer_value
- :player
- else
- :dealer
+ return :push if player_value == dealer_value
+ if player_value > dealer_value
+ return :player
+ else
@jwo

jwo Dec 1, 2012

Owner

The alignment here of the if/else seems off.. it was a bit hard to read (obviously not a big deal).

@jomarquez

jomarquez Dec 1, 2012

i think i was working on this part at 4 in the morning. my bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment