Created
November 17, 2009 04:02
-
-
Save shugo/236631 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
class Module | |
def append_features(base) | |
base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block") | |
end | |
def included(klass = nil, &block) | |
if block_given? | |
@_included_block = block | |
else | |
super if defined?(super) | |
end | |
end | |
end | |
module Foo | |
FOO = 1 | |
included do | |
p Module.nesting | |
puts FOO | |
end | |
end | |
class Bar | |
include Foo | |
# Ruby 1.8: 1 | |
# Ruby 1.9.current: error | |
# Ruby 1.9.shugo: 1 | |
end | |
class Baz | |
FOO = 2 | |
include Foo | |
# Ruby 1.8: 1 | |
# Ruby 1.9.current: 2 | |
# Ruby 1.9.shugo: 2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment