{"id":1069,"date":"2013-08-01T10:00:56","date_gmt":"2013-08-01T14:00:56","guid":{"rendered":"http:\/\/www.matthewgkeller.com\/blog\/?p=1069"},"modified":"2013-08-12T09:32:58","modified_gmt":"2013-08-12T13:32:58","slug":"ruby-string-each","status":"publish","type":"post","link":"http:\/\/www.matthewgkeller.com\/blog\/2013\/08\/01\/ruby-string-each\/","title":{"rendered":"Ruby String.each"},"content":{"rendered":"<p>While I find <a href=\"http:\/\/www.ruby-lang.org\/\">Ruby<\/a> to be a half-assed attempt at an object-oriented <a href=\"http:\/\/www.perl.org\/\">Perl<\/a>, I have been using it quite a bit lately to stay consistent with a lot of existing intellectual property. One of the more maddening things is that somewhere along the way, within the 1.9.x series, the Cardinals of Ruby decided to remove the &#8220;each&#8221; method from the String object. While logically inconsistent, this method allowed one to create a function that iterated over an array, or if the item passed was a String, iterate over that one item, without extra code to detect if it was &#8220;only&#8221; a String and handle it differently. Add the below to your rb or include it in a file to get that feature &#8220;back&#8221;.<\/p>\n<pre><code>\r\nclass ::String\r\n  def each(&amp;block)\r\n    Array(self).each(&amp;block)\r\n  end\r\nend\r\n<\/code><\/pre>\n<p>*sigh*<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While I find Ruby to be a half-assed attempt at an object-oriented Perl, I have been using it quite a bit lately to stay consistent with a lot of existing intellectual property. One of the more maddening things is that &hellip; <a href=\"http:\/\/www.matthewgkeller.com\/blog\/2013\/08\/01\/ruby-string-each\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10,14],"tags":[100,79],"class_list":["post-1069","post","type-post","status-publish","format-standard","hentry","category-general-coding","category-linuxy","category-rantstirades","tag-ruby","tag-stupid"],"_links":{"self":[{"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/posts\/1069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/comments?post=1069"}],"version-history":[{"count":0,"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/posts\/1069\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/media?parent=1069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/categories?post=1069"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.matthewgkeller.com\/blog\/wp-json\/wp\/v2\/tags?post=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}