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.
Diego V. (Guest)
on 2009-02-27 18: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
7stud -. (Guest)
on 2009-02-27 20:04
Diego V. 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
7stud -. (Guest)
on 2009-02-27 23:02
Diego V. 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.