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:

  >> 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.

Reply via email to