String -> symbol

ok - i'm officially an idiot.

i want to dynamically alias the names of all methods in a module... i need to string-manipulate the original method name to get the new one. alias_method only takes symbol names and the only tricks i know to convert strings to symbols (i.e., method("this_func") and SomeClass.method_eval("this_func) don't apply.

  my_module.instance_modules.each{ |m|
     m_new_name = <string stuff on m>
     alias_method <what goes here?> <and what goes here?>

more generally, is there some easy way to convert strings to symbols that i've missed?

thanks
m

"a_string".to_sym # => :a_string

enjoy,

-jeremy

···

On Wed, May 23, 2007 at 04:13:49AM +0900, mike.cahill@comcast.net wrote:

ok - i'm officially an idiot.

i want to dynamically alias the names of all methods in a module... i need to string-manipulate the original method name to get the new one. alias_method only takes symbol names and the only tricks i know to convert strings to symbols (i.e., method("this_func") and SomeClass.method_eval("this_func) don't apply.

  my_module.instance_modules.each{ |m|
     m_new_name = <string stuff on m>
     alias_method <what goes here?> <and what goes here?>

more generally, is there some easy way to convert strings to symbols that i've missed?

--

Jeremy Hinegardner jeremy@hinegardner.org

more generally, is there some easy way to convert strings to symbols that
i've missed?

Is String#to_sym (or String#intern) what you looking for?

V.

···

From: mike.cahill@comcast.net [mailto:mike.cahill@comcast.net]
Sent: Tuesday, May 22, 2007 10:14 PM

alias_method only takes symbol names

That isn't true. alias_method takes strings just fine:

>> class A; alias_method 'foo', 'to_s';end; A.new.foo
# => "#<A:0xb7cfcf08>"

···

mike.cahill@comcast.net wrote:

--
Florian Frank

String#to_sym

HTH,
Sebastian

···

mike.cahill@comcast.net wrote:

more generally, is there some easy way to convert strings to symbols that
i've missed?

--
Ist so, weil ist so
Bleibt so, weil war so

>more generally, is there some easy way to convert strings to symbols
>that i've missed?

Is String#to_sym (or String#intern) what you looking for?

Which one is in fact preferred?

- donald

Either one, they are synonymous.

···

On 5/22/07, Ball, Donald A Jr (Library) <donald.ball@nashville.gov> wrote:

> >more generally, is there some easy way to convert strings to symbols
> >that i've missed?
>
> Is String#to_sym (or String#intern) what you looking for?

Which one is in fact preferred?

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/