Created
May 16, 2012 14:37
-
-
Save etiennebarrie/2710836 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 'test/unit' | |
class A | |
def a | |
end | |
def method_missing(*) | |
end | |
end | |
class B < A | |
def method_missing(*) | |
end | |
end | |
class FooTest < Test::Unit::TestCase | |
def setup | |
@o = Object.new | |
end | |
def _test_method_name | |
assert(!@o.respond_to?(:method_missing)) | |
assert A.new.respond_to?(:method_missing) | |
assert B.new.respond_to?(:method_missing) | |
B.send :remove_method, :method_missing | |
assert A.new.respond_to?(:method_missing) | |
assert B.new.respond_to?(:method_missing) | |
end | |
def test_2 | |
assert(!@o.respond_to?(:method_missing)) | |
assert A.new.respond_to?(:method_missing) | |
assert B.new.respond_to?(:method_missing) | |
A.send :remove_method, :method_missing | |
assert !A.new.respond_to?(:method_missing) | |
assert B.new.respond_to?(:method_missing) | |
end | |
end | |
module FooBarBaz | |
module Foo | |
def foo_bar_baz | |
2 | |
end | |
end | |
include Foo | |
module Bar | |
def foo_bar_baz | |
super * 3 | |
end | |
end | |
include Bar | |
module Baz | |
def foo_bar_baz | |
super * 7 | |
end | |
end | |
include Baz | |
end | |
o = Object.new | |
o.extend FooBarBaz | |
meta_o = class << o; self; end | |
p meta_o.ancestors | |
p o.foo_bar_baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment