aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-05-06 19:06:49 -0700
committerPiotr Sarnacki <drogus@gmail.com>2012-05-06 19:07:21 -0700
commit3ac93d662933ee032227da0bcce57807c7d57889 (patch)
tree8567ac8a666003bd87db05126d0df1dae171fe98 /guides/source
parentb41bfb04b9e3e88b22f0d78c5f06c8cb44c5ae0a (diff)
downloadrails-3ac93d662933ee032227da0bcce57807c7d57889.tar.gz
rails-3ac93d662933ee032227da0bcce57807c7d57889.tar.bz2
rails-3ac93d662933ee032227da0bcce57807c7d57889.zip
[guides] Add comments to deep_dup example, fix second example [ci skip]
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/active_support_core_extensions.textile4
1 files changed, 3 insertions, 1 deletions
diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile
index ab5ceaf2b3..c56cb0b9e5 100644
--- a/guides/source/active_support_core_extensions.textile
+++ b/guides/source/active_support_core_extensions.textile
@@ -164,11 +164,13 @@ duplicate = array.dup
duplicate.push 'another-string'
+# object was duplicated, element added only to duplicate
array #=> ['string']
duplicate #=> ['string', 'another-string']
duplicate.first.gsub!('string', 'foo')
+# first element was not duplicated, it will be changed for both arrays
array #=> ['foo']
duplicate #=> ['foo', 'another-string']
</ruby>
@@ -179,7 +181,7 @@ If you need a deep copy of an object, you should use +deep_dup+ in such situatio
<ruby>
array = ['string']
-duplicate = array.dup
+duplicate = array.deep_dup
duplicate.first.gsub!('string', 'foo')