Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save markryall/346745 to your computer and use it in GitHub Desktop.
Save markryall/346745 to your computer and use it in GitHub Desktop.
irb --> RUBY_VERSION
==> "1.9.1"
irb --> module M
module A
def execute(&block)
instance_eval(&block)
end
end
end
module N
class B
end
class C
include M::A
def with_instance_eval
execute { B.new }
end
def without_instance_eval
B.new
end
end
end
==> nil
irb --> c = N::C.new
==> #<N::C:0x00000101030750>
irb --> c.without_instance_eval
==> #<N::B:0x0000010101ff48>
irb --> c.with_instance_eval
NameError: uninitialized constant N::C::B
irb --> c.instance_eval { B.new }
NameError: uninitialized constant N::C::B
irb --> c.instance_eval { N::B.new }
=> #<N::B:0x000001009b1930>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment