I need a function to get something in according to check if they meet some judgment, the judgement is some function which require parameters. such as:
Something.is_close_to?(:sky)
I already made one, with to what I learned in here.
def get_somethings(options = {})
somethings = []
Something.all.each do |something|
this_is_it = true
options.each_pair do |key, value|
expected_result = value.pop
this_is_it = false if !(Something.first.send(key, *value) == expected_result)
end
somethings << something if this_is_it
end
return somethings
end
and I can call this function via using someway like this:
options = {is_close_to?: ["sky", true], is_higher_than?: [2000, true]}
get_somethings()
I think my way is twisted, so I wonder if there are better way to do this.