[Newbies] Total newb...
Michael Haupt
mhaupt at gmail.com
Tue Oct 14 06:45:57 UTC 2008
Hi Tony,
On Tue, Oct 14, 2008 at 8:11 AM, Tony Giaccone <tony at giaccone.org> wrote:
> validHands := Set new.
> validHands add: Rock new; add Paper new; add Scissors new.
>
> Assume I have a player object which responds to the method throwsAHand with
> an instance of Rock Paper or Scissors.
>
> how do I craft
>
> validHands contains: aPlayer throwsAHand
'ere, how about this:
validHands anySatisfy: [ :elem | elem respondsTo: #throwsAHand ]
Collection >> #anySatisfy: takes a block and evaluates it for all the
elements in the collection. It returns true if the block evaluates to
true for any of the elements, and false otherwise.
Object >> #respondsTo: accepts a symbol (!) denoting a message name
and returns true if the object in question understands that message.
Did I make clear what the above code does?
Best,
Michael
More information about the Beginners
mailing list