Skip to content

Instantly share code, notes, and snippets.

@wapcaplet
Created March 27, 2012 17:05
Show Gist options
  • Save wapcaplet/2218003 to your computer and use it in GitHub Desktop.
Save wapcaplet/2218003 to your computer and use it in GitHub Desktop.
# When `person` is initialized, even if it's only set to nil, then the
# value is shared both inside and outside the block:
person = nil
Neo4j::Transaction.run do |tx|
person = Person.new(params)
puts "Inside block, person: #{person}"
end
puts "Outside block, person: #{person}"
# output:
# Inside block, person: #<Sherman::Core::Person:0x30fffd2c>
# Outside block, person: #<Sherman::Core::Person:0x30fffd2c>
# But when `person` is not initialized until we get to inside the block,
# then `person` is unavailable outside the block:
#person = nil # person not initialized
Neo4j::Transaction.run do |tx|
person = Person.new(params)
puts "Inside block, person: #{person}"
end
puts "Outside block, person: #{person}"
# output:
# Inside block, person: #<Sherman::Core::Person:0x1d8f6445>
# (exception occurs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment