Created
August 3, 2010 17:46
-
-
Save xwmx/506804 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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