(SOLUTION added at the end of the posting)
Say someone is giving me a class
class Foo
def self.bar
end
def baz
end
end
Without touching the original code, I would like to add an instance
method ‘bar’, which behaves exactly like ‘baz’. I can do it like this:
class Foo
def bar
self.baz
end
end
Semantically, this is fine, but it causes one extra redirection step. I
would like to use alias
class Foo
alias bar baz
end
but this doesn’t work, because ‘bar’ is already a class method.
Any solution for this?
UPDATE: I found the solution for this. It was actually easy - Ruby keeps
of course class methods and instance methods apart, and I can simply do
a
class Foo
alias :bar :baz
end
and everything works fine. I should have tried it in the beginning, but
I was so sure that it would not work…