The Pickaxe book asserts that it will be possible to pass a block to
Struct.new in Ruby 1.9. While spelunking the code, I discovered that the
functionality has actually been present since 1.8.3. I've blogged about
this here:

http://www.texperts.com/2007/09/03/hidden-feature-in-rubys-struct/

But reading this mailing list, I notice that there's another way to
achieve a similar effect, specifically deriving from Struct.new.

So, both of the following achieve broadly the same effect:

> Customer = Struct.new(:name, :address) do
>   def to_s
>     "Customer called '#{name}' living at '#{address}'"
>   end
> end

> class Customer < Struct.new(:name, :address)
>   def to_s
>     "Customer called '#{name}' living at '#{address}'"
>   end
> end

Which leads to the question, what *are* the differences, and should I
prefer one approach over the other?

Thanks in advance for any light you can cast on this!

Paul.
-- 
Posted via http://www.ruby-forum.com/.