# hash

DRY Migrations

I wanted to write a post about the many things that should be fixed with Rails.

Interestingly, Rails 3.1 fixes quite many of these.

Method_missing, Politely

In their Polite Programmer talk at Rubyconf, Jim Weirich and Chris Nelson pointed out that merely adding some behavior with method_missing wasn’t quite polite, as shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class StereoPlayer
  def method_missing(method, *args, &block)
    if method.to_s =~ /play_(\w+)/
      puts "Here's #{$1}"
    else
      super
    end
  end
end

p = StereoPlayer.new
# ok:
p.play_some_Beethoven # => "Here's some_Beethoven"
# not very polite:
p.respond_to? :play_some_Beethoven # => false

In order for respond_to? to return true, one can specialize it

Fixing MRI, a Dozen Steps at a Time

Is there a term like bugfield? You know, when everytime you get to take a couple of steps in a code base you encounter a different bug, which leads to another one, …, like a minefield of bugs?

Here was my last sequence in Ruby (MRI)…

Main goal: improve Matrix#determinant and #rank after a suggestion of Yu Ichino. The bulk of the work took me quite a while, as I had to check a bunch of things, understand the algorithm, do some performance testing, etc…

Best Time to Get Involved in Ruby Core

Apart from enjoying the summer, I’ve spent time hacking on MRI, especially since I’ve been accepted as a committer. The feature freeze for Ruby 1.9.2 was planned for yesterday and this has been pushed back a couple of days before. Rejoice!

Why?

Stickler in Silicon Valley

I have not been actively looking for a job yet. Nevertheless, I was contacted by a startup and invited to spend a week in Silicon Valley / San Francisco, hacking around with them to see if I could become part of their team, which I found quite flattering. I learned lots of new things in California. A couple of new words too. I’m still unsure as to what exactly a hipster is, but “stickler” was easier to grasp: one who insists on exactness or completeness in the observance of something.

A Schizo Ruby Puzzle

Quick quirky quiz (schizo version)

1
2
3
4
# Without writing any method/block/lambda,
# can you find ways to obtain, in Ruby 1.8.7 or 1.9:
x == y   # ==> true
y == x   # ==> false

Here’s how I got to checkout Ruby’s source and stumble upon that.

Lost in Recursion

Last time I asked a simple (but quite hard) Ruby quiz:

1
2
3
4
# Without writing any method/block/lambda,
# can you find ways to obtain, in Ruby 1.8.7 or 1.9:
x == y   # ==> true
y == x   # ==> false

Zombies Hashes Archaisms of Ruby Core

I just love hashes. So much so, I named my blog after them. I also like that the hash sign is used for comments, in Ruby, or the way hash resembles hatch, thus the messy graphic theme and all. But I really like hashes. They are like mini-objects (object hatchlings?) and I tend to use them to store all sorts of information or instead of many conditions with case x; when :a ...; when :b ....

So I was quite surprised to note that in Ruby, either it’s really easy and natural to create a hash (with the super nice {:key => value, ...} syntax) or