Created
October 19, 2011 14:15
-
-
Save holysugar/1298406 to your computer and use it in GitHub Desktop.
order sample?
This file contains 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
# "created_at/desc" とか書けるようにしていいなら(delimiter は相談.) | |
order_strings.map{|o| | |
name, order = o.split('/', 2) | |
column_names, | |
order = 'asc' if order != 'desc' | |
column_names.include?(name) ? "#{name} #{order}" : nil | |
}.compact.join(', ') | |
# あるいは | |
order_strings.map{|o| | |
_, name, order = o.match(/\A(.+?)(?:_(desc|asc))?\z/).to_a | |
next unless column_names.include?(name) | |
"#{name} #{order}" | |
}.compact.join(', ') | |
# あとは map + join じゃなく each_with_object を使うとか…… |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment