Skip to content

Instantly share code, notes, and snippets.

@toothrot
Created July 2, 2010 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toothrot/461620 to your computer and use it in GitHub Desktop.
Save toothrot/461620 to your computer and use it in GitHub Desktop.
blocks are funky.
outside = "foo"
classy = Class.new do
define_method(:get_thing) do
outside
end
def get_thing_with_def
outside
end
define_method(:curious) do
self
end
def def_curious
self
end
end
classy.new.get_thing # => "foo"
classy.new.get_thing_with_def # => NameError
classy.new.curious #=> classy instance
classy.new.def_curious #=> classy instance
outside = "bar"
classy.new.get_thing # => "bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment