Prev: Recommended way to install Rubygems
Next: gecode/r troubles with constraints definition in a CSP
From: Gary Wright on 17 Mar 2010 01:25 On Mar 17, 2010, at 1:15 AM, Sam Yang wrote: > Gary Wright wrote: >> On Mar 16, 2010, at 10:02 AM, Phillip Curry wrote: >> >>> I want to take an array of strings and convert each member to an integer. >>> array.to_i obviously doesn't work. >> >> => a = %w{1 2 3 4} >> => ["1", "2", "3", "4"] >>>> a.map! { |x| x.to_i } >> => [1, 2, 3, 4] > > simply > ["1","2"].collect(&:to_i) simply? Your alternative creates a new array and it seemed like the OP wanted to replace the elements in the existing array. And I don't think Symbol#to_proc is 'simple' for someone who isn't familiar yet with map/map! (or collect/collect!). Gary Wright
First
|
Prev
|
Pages: 1 2 Prev: Recommended way to install Rubygems Next: gecode/r troubles with constraints definition in a CSP |