Skip to content

Instantly share code, notes, and snippets.

@kenichi
Last active February 7, 2023 14:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenichi/f251b30c7c852b5e035a903754e2434d to your computer and use it in GitHub Desktop.
Save kenichi/f251b30c7c852b5e035a903754e2434d to your computer and use it in GitHub Desktop.
#!/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