Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
what symbol for class methods?
Diego Virasoro
2/27/2009 4:54:00 PM
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
2 Answers
7stud --
2/27/2009 6:04:00 PM
0
Diego Virasoro wrote:
> 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
--
Posted via
http://www.ruby-...
.
7stud --
2/27/2009 9:01:00 PM
0
Diego Virasoro wrote:
> 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 :old_greet, :greet
end
end
A.old_greet #hello
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
what symbol for class methods?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password