Skip to content

Instantly share code, notes, and snippets.

@marocchino
Forked from codian/gist:1369486
Created November 16, 2011 15:26
Show Gist options
  • Save marocchino/1370343 to your computer and use it in GitHub Desktop.
Save marocchino/1370343 to your computer and use it in GitHub Desktop.
alias_method_chain quiz
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