Skip to content

Instantly share code, notes, and snippets.

@mmontagna
Created February 9, 2018 19:48
Show Gist options
  • Save mmontagna/f762018fa92d8ce3195fa0d73f52eda7 to your computer and use it in GitHub Desktop.
Save mmontagna/f762018fa92d8ce3195fa0d73f52eda7 to your computer and use it in GitHub Desktop.
ruby alias methods
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