I'm working with ruby and I'm just learning lambdas. I have an array of objects and I want to select certain objects from the array based of different conditions like so:
result = array.select{|ar| ar.number > 4}
I want to put the arguments of the select into a lambda expression i.e. I want to put |ar| ar.number > 4
into a lambda expression. I've tried a few things including:
result = array.select{lambda{|g| g.number > 4}}
But this doesn't work.
I've also tried this:
l = lambda {g.number > 4}
result = array.select{|g| l}
and that also doesn't work. Also I need to pass my lambda express to a function so I don't think the first way I did it would have worked. How would I do this?