From: Robert Dober Date: 2007-03-16T21:21:58+09:00 Subject: Re: Anyone playing with higher order messaging in ruby? On 3/16/07, Christoffer Lern� wrote: > On Mar 14, 2007, at 23:48 , Benjohn Barnes wrote: > > > On 14 Mar 2007, at 19:57, Jason Roelofs wrote: > > > >> I haven't personally messed with this kind of stuff but code like > >> this just > >> makes me love Ruby even more. These types of, well DSL is really > >> the best > >> way to describe it, in such little code, makes Ruby such a blast > >> to program > >> in, and it's readable too! > > > > I think I must be getting too old, or I'm being a spring time > > Scrouge... > > > > While it's neat, and it's cool Ruby can do that stuff, I've got to > > ask "Why?". > > And another example: > > # A chat server where @clients = [connection1, connection2...] > # message = "Hello" > # sender = "Bob" > > # With normal each: > packet = BroadcastChatPacket.new("#{sender} says: #{message}") > @clients.each { |c| c.broadcast(packet) } > > # With each_do: > @clients.each_do.broadcast(BroadcastChatPacket.new("#{sender} says: # > {message}")) > > Eliminating the need for the temporary variable. > Do I understand correctly when I remark that a new BroadcastChatPacket instance is created or each iterator call in #each_do.broadcast, If not than it is just the same as @clients.each{ |c| c.broadcast BCP.new... } in this context I do not really see the practical interest though I *obviously* like that style as I have shown above. Well 6 months is a long time, but no I still like this magic dot notation. Cheers Robert > /Christoffer > > -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw