Skip to content

Instantly share code, notes, and snippets.

@tpo
Created March 7, 2011 13:40
Show Gist options
  • Save tpo/858515 to your computer and use it in GitHub Desktop.
Save tpo/858515 to your computer and use it in GitHub Desktop.
Pascal's WITH in ruby
# for a long time I wondered why Ruby didn't have Pascal's "WITH"
# construct. It's completely trivial to implent though...
def with object, &block
object.instance_eval(&block)
end
# now instead of needing to name your object all the time:
object = Object.new
object.foo
object.bazbar
# you can instead just do
with object do
foo
bazbar
end
# oh the simple wonders of metaprogramming :-o :-)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment