Forum: Ruby what symbol for class methods?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aae5c9f81fe990a48daf2bb91ac82759?d=identicon&s=25 Diego Virasoro (Guest)
on 2009-02-27 17:56
(Received via mailing list)
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
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-02-27 19:04
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
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-02-27 22:02
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
This topic is locked and can not be replied to.