Skip to content

Instantly share code, notes, and snippets.

@xwmx
Created August 3, 2010 17:46
Show Gist options
  • Save xwmx/506804 to your computer and use it in GitHub Desktop.
Save xwmx/506804 to your computer and use it in GitHub Desktop.
# http://news.ycombinator.com/item?id=1571894
# A quick tips when creating block DSLs in Ruby:
def search(&blk)
if blk.arity == 1
blk.call(self)
else
self.instance_eval(&blk)
end
end
# Then the user can decide what he want to use:
Foo.search { bar }
Foo.search { |s| s.bar }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment