Created
February 9, 2018 19:48
-
-
Save mmontagna/f762018fa92d8ce3195fa0d73f52eda7 to your computer and use it in GitHub Desktop.
ruby alias methods
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 A | |
class << self | |
def set_opt | |
self.instance_eval do | |
define_method(:foo) do | |
puts "wrapped!" | |
super() | |
puts "end wrap" | |
end | |
end | |
# self.class_eval do | |
# define_method(:perform_async) do | |
# puts "perform_async wrapped!" | |
# super() | |
# puts "perform_async end wrap" | |
# end | |
# # end | |
def perform_async | |
puts "orig async" | |
end | |
alias :ruby_is_stupid :perform_async | |
def perform_async | |
puts "new async" | |
ruby_is_stupid | |
end | |
end | |
end | |
def foo | |
puts 123 | |
end | |
end | |
class B < A | |
set_opt | |
end | |
A.perform_async |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment