Last active
February 7, 2023 14:52
-
-
Save kenichi/f251b30c7c852b5e035a903754e2434d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
class A | |
def b | |
'b' | |
end | |
end | |
module X | |
def b | |
"#{super}x" | |
end | |
end | |
module Y | |
def self.included base | |
base.class_eval do | |
alias_method :b_without_y, :b | |
alias_method :b, :b_with_y | |
end | |
end | |
def b_with_y | |
"#{b_without_y}y" | |
end | |
end | |
case ARGV[0] | |
when '--prepend' # bx | |
A.prepend X | |
when '--alias' # by | |
A.include Y | |
when '--both' # SystemStackError | |
A.prepend X | |
A.include Y | |
when '--flip' # byx | |
A.include Y | |
A.prepend X | |
end | |
puts A.new.b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment