# Forum: Ruby Euchre Hands (#55)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
on 2005-11-21 07:59
```#
# My Solution - unless a mail agent mangles it
# (happens with great frequency)
#

class Card
def initialize(string)
@value = string[0..-2].upcase
@suite = string[-1..-1].downcase
end
def to_i
case @value
when 'J': 11
when 'Q': 12
when 'K': 13
when 'A': 1
else
@value.to_i
end
end
def to_s
@value + @suite
end
end
class EuchreHand
def initialize(trump, cards)
@trump_string = trump
@trump = trump[0..0].downcase
@cards = cards
end
def to_s
([@trump_string] +@cards.sort_by {|c| sort_value(c)}).join("\n")
end
private
#there are 6 sections of the sort: jack1, jack2, trump, opp1, same,
opp2
def sort_value(card)
return [0] if card.value == 'J' && card.suite == @trump
same, opposite = [['h','d'],['c','s']].partition {|x|
x.include?(@trump)}
same[0].delete(@trump)
same = same[0][0]
opposite = opposite[0]
return [1] if card.value == 'J' && card.suite
suites = [@trump, opposite[0], same, opposite[1]]
return [2+suites.index(card.suite),-card.to_i]
end
end