From: Daniel Schierbeck Date: 2006-07-08T20:42:17+09:00 Subject: Re: newbie Q - calling a method for an object in an .each bl Robert Klemme wrote: > You could for example create individual classes for suit, face and > maybe also for value implementing the enum pattern, so you end up > having just a single instance for hearts, clubs, face_up, face_down > etc. I'd much rather stick with a single class, and use some of Ruby's goodness to get the magic: class Card SUITS = [:hearts, :clubs, :diamonds, :spades] RANKS = (1..13).to_a attr_reader :suit, :rank def initialize(suit, rank) @suit, @rank = suit.to_sym, rank.to_int raise unless SUITS.include? @suit raise unless RANKS.include? @rank end # creates the methods #hearts?, #clubs?, #diamonds?, and #spades? SUITS.each{|suit| define_method("#{suit}?"){ suit == @suit }} # etc. etc. end But that's a matter of opinion, of course. Cheers, Daniel