Archive for September, 2007

GuessMethod 0.1.0!

I’ve read around the internet that at RailsConfEurope, Dr. Nic used my baby GuessMethod as an example of fun that can be had with meta-programming. I’m flattered.

But flattery only lasts so long, and before I knew it I remembered that I had been wanting to fix it up a little. So I did.

As such, I’m pleased to announce version 0.1 of my little aggressive spelling corrector for irb.

sudo gem install guessmethod

And live the life!

003:0> Strin.tos
attention: replacing non-existant constant Strin with String for Object
attention: sending to_s instead of tos to String:Class
“String”

This is not for production! And it’s not for Rails either. It kills Rails. Until I figure out how to make GuessMethod not kill Rails, it will kill Rails.

That being said, I use it all the time. My irb sessions are full of pretty messages and corrected typos.

Enjoy!

Comments (1)

Installing 1.9

I finally got the 1.9 itch bad enough. I didn’t see any brainlessly simple “Install Ruby 1.9 alongside 1.8.x” guides, and as I’m relatively new to serious Unix-y system usage I like those kinds of things. Anyway, in the event that someone’s looking for a brainlessly simple “Install Ruby 1.9 alongside 1.8.x” guide:

svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby19
cd ruby19
autoconf
./configure --prefix=/usr/local --program-suffix=19 --with-readline-dir=/usr/local
make
sudo make install

Certainly, old hands have this down, and much of this is in the README. But the secret is --program-suffix=19, which leaves ruby alone and gives you ruby19 as your 1.9 executable.

Then I ran the benchmark stuff from this thread, and here’s how it went:

mvb:~ cms$ ruby calculate.rb
55

Ruby 1.8.6 patch 0 on i686-darwin8.9.1
It took 9.167413 seconds to run. 109082 iterations per
second.
mvb:~ cms$ ruby19 calculate.rb
55

Ruby 1.9.0 patch 0 on i686-darwin8.10.1
It took 3.059674 seconds to run. 326832 iterations per
second.

Comments (5)

macaddr

Ara Howard has just released a cross-platform MAC address reporting tool called macaddr. I read the code (it’s only 33 lines), and I’m glad I did. It’s like a little Ruby lesson on singleton methods.

Comments

A glimpse at the parser

Recently a user by the name of 7stud has been asking questions about Hash on comp.lang.ruby. In some curiosity fueled by his, I was playing around with this:

class Hash
  alias_method :old_get, []

  def [](key)
    puts #{key} => #{old_get(key)}
    old_get(key)
  end
end

I was expecting little more than (assuming a = {:b => ‘c’}):

003:0> a[:b]
b => c
"c"

But what I got (besides a whole bunch of irb config values and Wirble related output) included this:

a =>
a =>
[ => #<IRB::SLex::Node:0x13dce34>
: =>
: => #<IRB::SLex::Node:0x13dd514>
b =>
b =>
b =>
] => #<IRB::SLex::Node:0x13dd6cc>=>
] => RubyToken::TkRBRACK

 => #<IRB::SLex::Node:0x13df7b0>

It’s too late on a Sunday to look further, but it’s nice to see how much is right there for the gleaning.

Comments