On Tue, Feb 8, 2011 at 2:17 PM, Michael Pavling <[email protected]> wrote:
> On 8 February 2011 18:06, Phil Crissman <[email protected]> wrote: > > If you want to modify an array of strings, for example, you could do: > > arr = ["John", "Doe"] > > => ["John","Doe"] > > arr.each{|s| s.replace("blah") } > > => ["blah","blah"] > > s.replace actually modifies the object, instead of creating a new one. > > > > Also, depending on your use-case, consider the enumerable methods > ".inject", ".collect", et al: > Thanks... #inject is new to me and looks very cool. From what I understand collect and map are the same function, is that your understanding too? > > >> x = [1,2,3] > => [1, 2, 3] > >> x.collect { |y| y*y } > => [1, 4, 9] > >> > > http://www.ruby-doc.org/core/classes/Enumerable.html > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

