{"id":153,"date":"2014-03-05T17:48:37","date_gmt":"2014-03-06T01:48:37","guid":{"rendered":"http:\/\/www.tizianasellitto.it\/blog\/?p=153"},"modified":"2020-05-11T09:47:59","modified_gmt":"2020-05-11T16:47:59","slug":"ruby-and-its-destructive-methods","status":"publish","type":"post","link":"https:\/\/www.tizianasellitto.it\/blog\/?p=153","title":{"rendered":"Ruby and its destructive methods&#8230;"},"content":{"rendered":"<p style=\"text-align: justify;\">In ruby there are methods followed by a &#8220;!&#8221; symbol (exclamation mark). These methods alter the object itself.<\/p>\n<p style=\"text-align: justify;\">For example in the Array class there are two versions of shuffle method<br \/>\n<a href=\"http:\/\/ruby-doc.org\/core-2.0\/Array.html#method-i-shuffle\" target=\"_blank\" rel=\"noopener noreferrer\">shuffle<\/a> and <a href=\"http:\/\/ruby-doc.org\/core-2.0\/Array.html#method-i-shuffle-21\" target=\"_blank\" rel=\"noopener noreferrer\">shuffle!<\/a>.<\/p>\n<p style=\"text-align: center;\"><code> a = [1,2,3, 4] =&gt; [1, 2, 3, 4]<br \/>\na.object_id =&gt; 70279519801380<br \/>\na.shuffle.object_id =&gt; 70279519867040<br \/>\na.shuffle!.object_id =&gt; 70279519801380<br \/>\n<\/code><\/p>\n<ul>\n<li>Shuffle version returns a new array with elements of self shuffled and as a.shuffle.object_id shows a different value from a.object_id.<\/li>\n<li>shuffle! modifies the object itself,&nbsp; shuffling elements in self in place and a.shuffle!.object_id shows the same object_id of a.object_id.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In ruby there are methods followed by a &#8220;!&#8221; symbol (exclamation mark). These methods alter the object itself. For example in the Array class there are two versions of shuffle method shuffle and shuffle!. a = [1,2,3, 4] =&gt; [1, 2, 3, 4] a.object_id =&gt; 70279519801380 a.shuffle.object_id =&gt; 70279519867040 a.shuffle!.object_id =&gt; 70279519801380 Shuffle version returns [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[19,14],"tags":[32,18],"_links":{"self":[{"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/posts\/153"}],"collection":[{"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=153"}],"version-history":[{"count":3,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":285,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions\/285"}],"wp:attachment":[{"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}