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 =
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

On Wed, May 23, 2007 at 04:13:49AM +0900, [email protected] 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 =
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?

“a_string”.to_sym # => :a_string

enjoy,

-jeremy

From: [email protected] [mailto:[email protected]]
Sent: Tuesday, May 22, 2007 10:14 PM

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.

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

[email protected] wrote:

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>”

[email protected] wrote:

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

String#to_sym

HTH,
Sebastian

On 5/22/07, Ball, Donald A Jr (Library) [email protected]
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?

Either one, they are synonymous.


Rick DeNatale

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs