From: Josh Cheek Date: 2010-06-21T23:17:58+09:00 Subject: Re: Ruby Basic --001636456ff088861a04898af8ac Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jun 21, 2010 at 5:52 AM, Raveendran .P wrote: > Hi All, > > def one > puts "hi" > end > > Once i call one --> i can able to get a output. > > > QUESTION: > > I have a array method_list=["one"] > > How can I convert "one" to method ? > -- > Posted via http://www.ruby-forum.com/. > > In general, you can convert a string / symbol to the method it is maning by using the method "method" http://ruby-doc.org/core/classes/Object.html#M000336 def one() "hi" end def two() "hello" end def three() "hola" end method_names = private_methods(false).reject { |name| name.size > 5 } method_names # => ["three", "two", "one"] method_list = method_names.map { |name| method name } method_list # => [#, #, #] method_results = method_list.map { |meth| meth.call } method_results # => ["hola", "hello", "hi"] --001636456ff088861a04898af8ac--