Reputation: 24886
I want to create another name for a method that already exists, e.g. I want to call slice
with only
. I don't want to change anything about the behavior of that original method, so it's not a redefinition, but delegation. How can I do that?
Upvotes: 0
Views: 66
Reputation: 7616
There are a number of ways to do that in Ruby. Please check this post which may help you find your most suitable way of doing it.
http://gdakram.com/past/2010/12/2/multiple_ways_in_implementing_delegation_pattern_in_ruby/
Upvotes: 1
Reputation: 9197
class Whatever
def slice
# do something
end
alias :only :slice
end
Upvotes: 1