how to call a functino through a variable name 
Author Message
 how to call a functino through a variable name

How would I do something like this:

def blah
puts "string"
end

a = "blah"

run function defined by a.

--
Feb 12  Abraham Lincoln born, 1809
Feb 12  Charles Darwin born in Shrewsbury, England, 1809
Feb 12  Lincoln's real birthday
Feb 12  Santa Barbara oil leak, 1969
Feb 12  Pyidaungsa Day in Burma
Feb 12  The Beatles play Carnegie Hall in New York City, 1964
Feb 12* Rosh Chodesh Adar (Beginning of the month of Adar)



Mon, 01 Aug 2005 08:04:54 GMT  
 how to call a functino through a variable name
String.send

got it :)
nm

Quote:

> How would I do something like this:

> def blah
> puts "string"
> end

> a = "blah"

> run function defined by a.

> --
> Feb 12     Abraham Lincoln born, 1809
> Feb 12     Charles Darwin born in Shrewsbury, England, 1809
> Feb 12     Lincoln's real birthday
> Feb 12     Santa Barbara oil leak, 1969
> Feb 12     Pyidaungsa Day in Burma
> Feb 12     The Beatles play Carnegie Hall in New York City, 1964
> Feb 12*    Rosh Chodesh Adar (Beginning of the month of Adar)

--
Feb 12  Abraham Lincoln born, 1809
Feb 12  Charles Darwin born in Shrewsbury, England, 1809
Feb 12  Lincoln's real birthday
Feb 12  Santa Barbara oil leak, 1969
Feb 12  Pyidaungsa Day in Burma
Feb 12  The Beatles play Carnegie Hall in New York City, 1964
Feb 12* Rosh Chodesh Adar (Beginning of the month of Adar)


Mon, 01 Aug 2005 08:11:34 GMT  
 how to call a functino through a variable name
Try:

  eval a

Chris

Quote:
----- Original Message -----


Sent: Wednesday, February 12, 2003 4:04 PM
Subject: how to call a functino through a variable name

How would I do something like this:

def blah
puts "string"
end

a = "blah"

run function defined by a.

--
Feb 12 Abraham Lincoln born, 1809
Feb 12 Charles Darwin born in Shrewsbury, England, 1809
Feb 12 Lincoln's real birthday
Feb 12 Santa Barbara oil leak, 1969
Feb 12 Pyidaungsa Day in Burma
Feb 12 The Beatles play Carnegie Hall in New York City, 1964
Feb 12* Rosh Chodesh Adar (Beginning of the month of Adar)



Mon, 01 Aug 2005 08:17:59 GMT  
 how to call a functino through a variable name
Quote:

> def blah
> puts "string"
> end
> a = "blah"
> run function defined by a.

eval(a)

--
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]



Tue, 02 Aug 2005 03:27:58 GMT  
 how to call a functino through a variable name

Quote:


> > def blah
> > puts "string"
> > end
> > a = "blah"
> > run function defined by a.
> eval(a)

But it's more efficient to do:

  self.send(a)

Regards,

Brian.



Tue, 02 Aug 2005 04:21:23 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Using a variable name for a variable name??

2. Calling a procedure with a variable procedure name

3. call procedure named in a variable?

4. Call by name (in a variable)

5. calling a method using a variable name?

6. field name and key name as a variable

7. field name and key name as a variable

8. variable contents to variable name

9. array name in variable variable

10. getting variable name from the variable itself?

11. Variables containing variable names

12. name of a variable stored in another variable

 

 
Powered by phpBB® Forum Software