How do i run the function?

If i want to run a function whose name is contained in a string, how do
I do that in Ruby? or is this not feasible?

For example

  def a
    puts "a"
  end

  def b
    puts "b"
  end

  mymethod="a"

In the above code snippet, i like to run the function a by using the
string mymethod. What trick if any can i use in ruby to make this
happen?

Thanks.

···

--
Posted via http://www.ruby-forum.com/.

Object#send. class Object - RDoc Documentation (It'll take a string as well as a symbol.)

C

···

On 28 Dec 2010, at 23:37, Rick Tan wrote:

If i want to run a function whose name is contained in a string, how do
I do that in Ruby? or is this not feasible?

For example

def a
   puts "a"
end

def b
   puts "b"
end

mymethod="a"

In the above code snippet, i like to run the function a by using the
string mymethod. What trick if any can i use in ruby to make this
happen?

---
Caius Durling
caius@caius.name
+44 (0) 7960 268 100
http://caius.name/