Using Ruby's gsub with a block
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...
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...
Today’s topic is the following rule from the Ruby Style Guide: Add underscores to large numeric literals to improve their readability. Most of the programs we write feature a substantial numb...
RuboCop 0.9 is finally out! This was one of our most ambitious releases - over a month of work, ~250 commits, lots of new cops and features and a lot less bugs.1 Here’s the highlights. Portable Li...
Today’s topic is the following rule from the Ruby Style Guide: Favor the use of Array#join over the fairly cryptic Array#* with a string argument. Array#join and Array#* (with a string argume...