RubyFlow The Ruby and Rails community linklog

Floats as array indexes: [ 1, 2 ][0.5] == 1.5 (Why? Because it's silly, that's why.)

The best jokes have have a huge build-up to the punch line. My build-up is writing a whole gem, Array-subindex, and the punch line is being able to index an array with classes of number other than integers. Confuse your friends and astound your enemies with code like this: > [ 1, 2 ][0.5] > # => 1.5

[ 1, 2, 3 ][Rational(2,3)] # => 2.5

%w[ foo bar baz ][1.5] # => “arb” </code> It’s fun for the whole family and breaks the ice at parties!

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in