Is it possible to set a hash with values like <
, >
, %
, +
, etc.? I want to create a method that takes an array of ints and a hash with parameters.
In the method below, array
is the filtered array, and hash
is the parameters. The idea is that any number is less than min
or more than max
.
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
Desired Results:
array=[1, 25, 15, 7, 50] filter={min=> 10, max=> 30} range_filter(array, filter)
source share