Ruby - Using lambda with array each method


The following code iterates over an array of strings, capitalizing each string in turn.

The array of capitalized strings is then assigned to the d1 variable:


d = lambda{|x| x.capitalize! }
d1 = ["hello","good day","how do you do"].each{ |s|}
puts(d1.inspect)        #=> ["Hello", "Good day", "How do you do"]
# from   w w  w  .  j a  v  a  2s  . com


Related Topic