I am currently working on a Poker game in Ruby. Instead of using numerous if-else statements to check the value of the player's hand, I decided to do the following:
#calculate the players score
def score
POSS.map {|check|
if (check[1].call())
@score = check[0]
puts @score
return check[0]
else
false
end
}
end
POSS = [
[10, :royal_flush?],
[9, :straight_flush?],
[8, :four_kind?],
[7, :full_house?],
[6, :flush?],
[5, :straight?],
[4, :three_kind?],
[3, :two_pairs?],
[2, :pair?]
]
The second item in each item of 'POSS' is a method I created to check whether the player has that hand. I am attempting to call the method with .call(), but get the following error:
Player.rb:43:in `block in score': undefined method `call' for
:royal_flush?:Symbol (NoMethodError) from Player.rb:42:in `map' from
Player.rb:42:in `score' from Player.rb:102:in `get_score' from
Player.rb:242:in `<main>'