Lamda to a Method: {} vs do/end


#1

I was able to get the below code to work with the do/end commands but not the single line version with {}. Below are both versions with the {} commented out. my question is why i was able to do it with the do/end format and not the single line format.

crew = {
captain: "Picard",
first_officer: "Riker",
lt_cdr: "Data",
lt: "Worf",
ensign: "Ro",
counselor: "Troi",
chief_engineer: "LaForge",
doctor: "Crusher"
}

'#Add your code below!
'#first_half = lambda {|rank,name| name < "M"|}
'#first_half = lambda{|k,v| v < "M"|}

first_half = lambda do |k,v| v < "M"
end
a_to_m = crew.select(&first_half)


#2

This is all fairly new to me so it usually involves hours of digging through documentation to end up with a simple solution. I did get this to work:

first_13 = lambda { |key,value| value < "M"}
a_m = crew.select(&first_13)
puts a_m

Sorry I couldn't be more help.


#3

The problem is your final |, it shouldn't be there.