From: Robert Dober Date: 2007-03-17T07:31:29+09:00 Subject: Re: Anyone playing with higher order messaging in ruby? On 3/16/07, Christoffer Lern� wrote: > > On Mar 16, 2007, at 13:21 , Robert Dober wrote: > > > On 3/16/07, Christoffer Lern� wrote: > >> 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, > > No, each_do will only create BroadcastChatPacket once. > > /Christoffer > > Sure got confused it is evaluated in method_missing only once, good, thx for clarifying, I see the practical benefit now too. Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw