R
RichardOnRails
Hi,
I'm on a Ruby self-improvement mission. Presently I working my way
though all 47 of the Enumerable methods in Ruby 1.9.2. I composed the
following:
greek = %w{Alpha Beta Gamma}
puts greek.all? { |s| s.length == 5 } # (correct) => false
puts greek.all? { |s| (4..5).include? s.length } # (correct) => true
puts greek.all?(&:length) # (programmer error) => true
The last line is programmed incorrectly because I couldn't stick in
the intended "5" in a syntactically correct way. Is the most
effective way construction of a lamda/proc? If so, how?
Thanks in advance,
Richard:
I'm on a Ruby self-improvement mission. Presently I working my way
though all 47 of the Enumerable methods in Ruby 1.9.2. I composed the
following:
greek = %w{Alpha Beta Gamma}
puts greek.all? { |s| s.length == 5 } # (correct) => false
puts greek.all? { |s| (4..5).include? s.length } # (correct) => true
puts greek.all?(&:length) # (programmer error) => true
The last line is programmed incorrectly because I couldn't stick in
the intended "5" in a syntactically correct way. Is the most
effective way construction of a lamda/proc? If so, how?
Thanks in advance,
Richard: