Skip to content

Instantly share code, notes, and snippets.

@bkempner
Created November 10, 2011 20:25
Show Gist options
  • Save bkempner/1356099 to your computer and use it in GitHub Desktop.
Save bkempner/1356099 to your computer and use it in GitHub Desktop.
class Foo
def initialize
yield(self) if block_given?
end
end
# Shouldn't these be equivalent? Why isn't thing1 created?
f1 = Foo.new { |me| @thing1 = 'this is thing1' }
f1.instance_variable_get("@thing1") #=> nil
f1.instance_eval { @thing2 = 'this is thing2' }
f1.instance_variable_get("@thing2") #=> 'this is thing2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment