Is there any way to set a hash with values such as <
, >
, %
, +
, etc?
I want to create a method that accepts an array of ints, and a hash with parameters.
In the method below array
is the array to be filtered, and hash
is the parameters. The idea is that any number less than min
or more than max
is removed.
def range_filter(array, hash)
checker={min=> <, ,max => >} # this is NOT working code, this the line I am curious about
checker.each_key {|key| array.delete_if {|x| x checker[key] args[key] }
array.each{|num| puts num}
end
The desired results would be
array=[1, 25, 15, 7, 50]
filter={min=> 10, max=> 30}
range_filter(array, filter)
# => 25
# => 15