Lambdas/Procs in Case Expressions
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...
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...
I often see people writing code like this: if x % 2 == 0 ... Obviously Fixnum#even? would have been a better choice: if x.even? ... There is also Fixnum#odd? if you need to check for odd numb...
Prelude In the last few days Paul Stamatiou’s article Android is Better and Marco Arment’s excellent response Google Blindness have been generating a lot of heated debates. This article is pretty ...
Today we’ll discuss the following section from the Ruby Style Guide: Avoid explicit use of the case equality operator ===. As it name implies it’s meant to be used implicitly by case expression...
Today we’ll talk about attributes in Ruby. Let’s start with the following rule from the Ruby Style Guide: Use the attr family of functions to define trivial accessors or mutators. Everyone w...