Skip to content

Instantly share code, notes, and snippets.

@codian
Created November 16, 2011 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codian/1369486 to your computer and use it in GitHub Desktop.
Save codian/1369486 to your computer and use it in GitHub Desktop.
alias_method_chain quiz
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