From: Boris Schmid Date: 2009-02-09T03:57:43+09:00 Subject: Re: calling random Am I correct if I remember that using send is quite expensive in cpu-time? Especially when I am using it millions of times.. $pop is about 5000 hosts large. 10000.times { # Events to happen to every host this 0.1 year: ["birth","death","infect","evolve"].shuffle.each {|event| next if event == "birth" and EVENTS_BIRTH > rand next if event == "death" and EVENTS_DEATH > rand next if event == "infect" and EVENTS_INFECTION > rand next if event == "evolve" and EVENTS_EVOLUTION > rand $pop.each {|host| next if host == nil send(event,host) } } } What I could do is make birth,death,infect and evolve methods of the host class, and perhaps use call then. Does that make sense? David A. Black wrote: > Hi -- > > On Mon, 9 Feb 2009, Boris Schmid wrote: > >> end >> >> irb(main):008:0> [f1,f2].each {|fun| [1,2,3,4].each {|val| fun(val)}} > > If f1 and f2 contain actual method objects, you can use call: > > f1,f2 = method(:f1), method(:f2) > [f1,f2].each {|m| [1,2,3,4].each {|e| m.call(e) } } > > Mixing f(unction) and m(ethod) terminology a bit... but that's OK, > because it will also work if f1 and f2 are Proc objects (which are > basically anonymous functions. > > If you have strings or symbols, you can use them to get the method > objects (see above), or you can use send: > > ["f1", "f2"].each {|m| [1,2,3,4].each {|e| send(m,e)} } > > > David > > -- > David A. Black / Ruby Power and Light, LLC > Ruby/Rails consulting & training: http://www.rubypal.com > Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) > > http://www.wishsight.com => Independent, social wishlist management! -- Posted via http://www.ruby-forum.com/.