Is there a way to create a lambdas array or a procs array in ruby? I was able to define the arrays of each, but I could not understand the syntax of calling lambdas / procs in the array.
As a silly compiled example, consider this:
a = [ 1, 2, 3, 4, 5, 6, 7, 8]
b = [2, 3, 5, 7, 10]
c = [
Proc.new { |x| a.include? x },
Proc.new { |x| true },
Proc.new { |x| b.include? x }
]
def things_checker(element, checks)
z = 0
checks.each do |check|
p z
break unless check(element)
z = z + 1
end
end
things_checker(3, c)
I cannot figure out how to get check(element)
, so as not to be a syntax error.
source
share