Skip to content

Instantly share code, notes, and snippets.

@osdrv
Created March 21, 2012 06:12
Show Gist options
  • Save osdrv/2145123 to your computer and use it in GitHub Desktop.
Save osdrv/2145123 to your computer and use it in GitHub Desktop.
class A
attr_accessor :b
def with_b( new_b, &blk )
original_b = b
self.b = new_b
yield if block_given?
self.b = original_b
end
end
a = A.new
a.b = 1
with_b 2 do
p a.b # outputs 2
end
p a.b # outputs 1, no primary object state changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment