Regexp anchors in Ruby
Some Rubyists, when faced with the task of matching against the beginning or the end of a string, are prone to using ^ and $ in their regular expressions. Most of the time the code will seem to wor...
Some Rubyists, when faced with the task of matching against the beginning or the end of a string, are prone to using ^ and $ in their regular expressions. Most of the time the code will seem to wor...
Good news, everyone - RuboCop 0.14 was just released! Generally I announce RuboCop releases in only 140 characters, but this time I’ll make an exception. This release is more significant than most...
Recently we discussed how you can use String#gsub with a block. Today we’ll examine another somewhat unknown feature of the gsub method - the ability to supply a replacement hash as the second argu...
There are whopping 4 ways to invoke a lambda (or a proc) in Ruby: lambda.call(arg1, arg2) lambda[arg1, arg2] lambda.(arg1, arg2) # works only with one argument lambdas lambda === arg The last...
Most Rubyists know they can use literals, classes, ranges and regular expressions in the when branches of a case expression: case something when Array then ... when 1..100 then ... when /some_rege...
For better or for worse Perl had significant influence over Ruby’s initial design. A lot of things were directly borrowed from Perl, but over the years the Ruby community rejected most of the Perli...
Ruby’s Enumerable module is pretty extensive, but from time to time I wish it had some extra methods, that are available in the standard libraries of other languages like Scala, Groovy, Haskell and...
String#gsub is one of the most used Ruby methods in the wild. Just about every Ruby programmer knows about the method and uses it fairly regularly. Here’s a quick refresher of the typical gsub usa...
One can often find similar code in the wild: some_hash.has_key?(some_key) has_something? predicates are not idiomatic in Ruby and Hash#has_key? and Hash#has_value? are nothing, but remnants of t...
Powerpack is a small Ruby library containing (at this point) a few extensions to some core Ruby classes. I guess that in a way one can say it’s something like Rails’s ActiveSupport, but with much s...