The Elements of Style in Ruby #12: proc vs Proc.new
People are often confused about the fact that there are two ways to created procs in Ruby - via Kernel#proc and Proc.new. Let’s see them in action: Proc.new { true } # => #<Proc:0x007fe35440...
People are often confused about the fact that there are two ways to created procs in Ruby - via Kernel#proc and Proc.new. Let’s see them in action: Proc.new { true } # => #<Proc:0x007fe35440...
2013 was a good year for me in many aspects. I’ll share here some of the programming-related achievements of mine over the year that made me somewhat proud of myself. Achievements Ruby RuboCop...
Projectile 0.10.0 is out! This might come as a surprise for people tracking Projectile’s development, since recent snapshots were using 1.0 as the version number, so allow me to explain. I’ve been...
Sometimes we’d like to build a new collection object from the elements of another collection. One trivial example would be element occurrence counting, which basically means you need to build a ha...
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...