-
-
Save marocchino/1370343 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
require 'test/unit' | |
require 'rubygems' | |
gem 'activesupport' | |
require 'active_support/core_ext/module' | |
class Original | |
def hello | |
"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 + "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 + "FeatureB" | |
end | |
end | |
Original.class_eval do | |
include FeatureA | |
include FeatureB | |
end | |
#### 수정내용 ###### | |
class Original | |
def hello_without_feature_b | |
hello_without_feature_a + "FeatureC" | |
end | |
end | |
# 테스트 가능하도록 메서드를 조금 변경했어요. | |
################### | |
class OriginalTest < Test::Unit::TestCase | |
def setup | |
@original = Original.new | |
end | |
# def teardown | |
# end | |
def test_hello | |
assert_equal("OriginalFeatureCFeatureB", @original.hello) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment