Skip to content

Instantly share code, notes, and snippets.

@shugo
Created November 17, 2009 04:02
Show Gist options
  • Save shugo/236631 to your computer and use it in GitHub Desktop.
Save shugo/236631 to your computer and use it in GitHub Desktop.
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