Created
November 16, 2011 07:06
-
-
Save codian/1369486 to your computer and use it in GitHub Desktop.
alias_method_chain quiz
This file contains hidden or 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 Original | |
def hello | |
puts "Original" | |
end | |
end | |
module FeatureA | |
def self.included(base) | |
base.class_eval do | |
alias_method_chain :hello, :feature_a | |
end | |
end | |
def hello_with_feature_a | |
hello_without_feature_a | |
puts "FeatureA" | |
end | |
end | |
module FeatureB | |
def self.included(base) | |
base.class_eval do | |
alias_method_chain :hello, :feature_b | |
end | |
end | |
def hello_with_feature_b | |
hello_without_feature_b | |
puts "FeatureB" | |
end | |
end | |
Original.class_eval do | |
include FeatureA | |
include FeatureB | |
end | |
Original.new.hello | |
# 실행 결과는 아래와 같이 출력됩니다. | |
# | |
# Original | |
# FeatureA | |
# FeatureB | |
# | |
# 위 코드를 변경하지 않고 아래와 같이 출력되게 하려면 어떻게 패치해야 할까요? | |
# | |
# Original | |
# FeatureC | |
# FeatureB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment