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)

String.send

got it :slight_smile:
nm

···

On Thu, Feb 13, 2003 at 09:04:54AM +0900, Daniel Bretoi wrote:

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)

Try:

eval a

Chris

···

----- Original Message -----
From: “Daniel Bretoi” lists@debonair.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
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)

eval(a)

···

On Thu, Feb 13, 2003 at 09:04:54AM +0900, Daniel Bretoi wrote:

def blah
puts “string”
end
a = “blah”
run function defined by a.

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

But it's more efficient to do:

  self.send(a)

Regards,

Brian.

···

On Fri, Feb 14, 2003 at 04:27:58AM +0900, gminick wrote:

On Thu, Feb 13, 2003 at 09:04:54AM +0900, Daniel Bretoi wrote:
> def blah
> puts "string"
> end
> a = "blah"
> run function defined by a.
eval(a)