From: Ken Mitchell Date: 2007-04-06T07:35:54+09:00 Subject: Re: Run some method based on some condition --=-tJ5pZwug/FxTbjz7vXPE Content-Type: text/plain Content-Transfer-Encoding: 7bit Yes that does exactly what I wanted. ['a','b','c'].do {|x| ob.send(x)} On Fri, 2007-04-06 at 07:30 +0900, Jeremy McAnally wrote: > Something like this would work: > > irb(main):008:0> x = ['chop!', 'chop!', 'chop!'] > => ["chop!", "chop!", "chop!"] > irb(main):009:0> y = "This is a string!!!" > => "This is a string!!!" > irb(main):010:0> x.each {|method| y.send(method)} > => ["chop!", "chop!", "chop!"] > irb(main):011:0> y > => "This is a string" > > The send method allows you to do what you're asking. :) > > --Jeremy > > On 4/5/07, Ken Mitchell wrote: > > > > Say I wanted to run a method based on a condition like so: > > > > class Klass > > def initialize > > a = '1st' > > b = '2nd' > > c = '3rd' > > end > > > > def a > > a > > end > > > > def b > > b > > end > > > > def c > > c > > end > > end > > > > ob = Klass.new > > ['a','b','c'].do {|x| ob. **here I would want to get at #a and #b and #c** > > > > or maybe better explained like this > > > > var = 'a' > > > > puts ob.** ???? ** > > > > Or if you know perl > > $foo = {bar => "baz"}; > > $baz = "bar"; > > > > puts $foo->{$baz}; > > > > ---> baz > > > > Sorry to be so confusing. > > > > > > > > > > > > Thanks, > > > > Ken Mitchell > > -- > > > > Farmers Wireless > > Office: (256)638-4040 x 224 > > Mobile: (256)899-3391 > > Fax: (256)638-2110 > > kmitchell@farmerswireless.com > > > > > > > > CONFIDENTIALITY NOTICE: This e-mail and any attachment to it may contain > > confidential and legally privileged information. This information is > > intended only for the recipient named above. If you are not the intended > > recipient, take notice that any disclosure, copying, distribution or taking > > of any action based upon this information is prohibited by law. If you have > > received this e-mail in error, please return it to the sender and delete > > this copy from your system. Thank you. > > > > > > > > > -- Ken Mitchell --=-tJ5pZwug/FxTbjz7vXPE--