2006/7/8, william robb <otherwill / yahoo.com>:
> Logan Capaldo wrote:
> >
> >
> > It's working but #each returns the array and your #show method
> > returns a string, it doesn't have any side effects. You may want to
> > use map instead or use puts
> >
> > e.g.:
> >
> > hand.each { |c| puts c.show }
> >
> > or hand.map { |c| c.show }
>
> Ah!  These work.  Thank You!
>
> I do recall from pickax that #each returns the array.  It must be, then,
> with
>
> >hand.each { |c| c.show }
>
> what I am seeing how irb displays an array.

IRB uses method #inspect of any object for display.

>  Does this mean that the
> string returned by #show is produced, but nothing is telling it to
> display so it sort of ... gets assigned to nothing, and dosn't display
> in irb?

It doesn't even get assigned. The return value of #show is simply ignored.

> But, then, why doesn't the block with the puts call first display the
> strings followed by the display of the array returned by #each?

That we can only tell if you show us the code you used.  Normally it's
exactly like you describe:

irb(main):004:0> %w{aa bb cc}.each {|c| puts c}
aa
bb
cc
=> ["aa", "bb", "cc"]

> Follwing is the code defining the class (the rest I am just testing in
> irb) for hal fulton, who asked for it.  This is my first every ruby
> program so it may be ugly, and could probably be improved upon.  Been
> programming in procedural languages since fortran 77, so this OO stuff
> is a bit mind bending.  But ... I like it!

Yeah, it took me some while to grasp it when I learned OO (Turbo
Pascal at that time).  But the OO paradigm is much stronger than plain
procedural code IMHO.

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.

Kind regards

robert

-- 
Have a look: http://www.flickr.com/photos/fussel-foto/