Last active
August 21, 2017 06:15
-
-
Save s-ashwinkumar/6fdf4220bd3b8ef7c037861b4e38253f to your computer and use it in GitHub Desktop.
A sample for alias method in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass | |
def old_method | |
'old_method OR new_method' | |
end | |
alias :new_method :old_method | |
# NOTE-1 : 'alias' is a keyword and not a method, that is why | |
# there is no comma (I almost everytime type a comma there !) | |
# NOTE-2 : If you want to use the method kind of syntax you can use | |
# the 'method' Module#alias_method which does the same thing | |
# but is actually a method. | |
# so it would be 'alias_method :new_method, :old_method' | |
end | |
obj = MyClass.new | |
#=> #<MyClass:0x00000001859f48> | |
obj.old_method | |
#=> "old_method OR new_method" | |
obj.new_method | |
#=> "old_method OR new_method" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment