Created
April 21, 2020 06:27
-
-
Save aergonaut/44902d86193fc4135494940278689cde 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
require "bundler/inline" | |
gemfile do | |
source "https://rubygems.org" | |
gem "activesupport", "~> 4.2" | |
end | |
require "active_support/all" | |
class Dog | |
def speak | |
"woof!" | |
end | |
end | |
module British | |
def speak | |
"#{super} eh, wot?" | |
end | |
end | |
class BritishDog < Dog | |
prepend British | |
end | |
puts "only prepend: #{BritishDog.new.speak}" | |
class Cat | |
def speak | |
"meow!" | |
end | |
end | |
module Pirate | |
def self.included(base) | |
base.class_eval do | |
alias_method_chain :speak, :pirate_accent | |
end | |
end | |
def speak_with_pirate_accent | |
"#{speak_without_pirate_accent} yarr!" | |
end | |
end | |
class PirateCat < Cat | |
include Pirate | |
end | |
puts "only a_m_c: #{PirateCat.new.speak}" | |
class Duck | |
def speak | |
"quack!" | |
end | |
end | |
class PirateBritishDuck < Duck | |
include Pirate | |
prepend British | |
end | |
puts "a_m_c then prepend: #{PirateBritishDuck.new.speak}" | |
class Bear | |
def speak | |
"growl!" | |
end | |
end | |
class BritishPirateBear < Bear | |
prepend British | |
include Pirate | |
end | |
puts "prepend then a_m_c: #{BritishPirateBear.new.speak}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like I independently rediscovered something NewRelic discovered ages ago https://gist.github.com/kenichi/f251b30c7c852b5e035a903754e2434d