what symbol for class methods?

D

Diego Virasoro

Hello,
some methods require as an argument a symbol of a method (e.g.
alias_method). How can one use it with class methods?

Thanks.

Diego
 
7

7stud --

Diego said:
Hello,
some methods require as an argument a symbol of a method (e.g.
alias_method). How can one use it with class methods?

Thanks.

Diego

class A
def A.show(symbol)
puts "%s <--> %s" % [symbol.inspect, symbol.to_s]
end
end

A.show:)hello)

--output:--
:hello <--> hello
 
7

7stud --

Diego said:
Hello,
some methods require as an argument a symbol of a method (e.g.
alias_method). How can one use it with class methods?

Hmm...what does 'it' refer to? Does 'it' refers to alias_method?

As far as I can tell, you can't use alias_method with symbols like:

:self.meth_name

for arguments. However, this seems to work:

class A
def self.greet
puts "hello"
end

class<<self
alias_method :eek:ld_greet, :greet
end

end

A.old_greet #hello
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top