Created
August 27, 2015 17:55
-
-
Save ainame/deb182457b740d407029 to your computer and use it in GitHub Desktop.
ChainQuery allow you to build query by method chains.
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
class ChainQuery | |
def initialize(init_value) | |
@init_value = init_value | |
@filters = [] | |
end | |
def add_filter(&block) | |
@filters << block | |
self | |
end | |
def value | |
@filters.reduce(@init_value) {|last_value, filter| filter.call(last_value) } | |
end | |
end |
Author
ainame
commented
Aug 27, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment