hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Someone's Growing an Annotator for Himself and Others #

by why in inspect

If you haven’t already subscribed, Mauricio Fernandez’ new blog at eigenclass.org is the most exciting blogride on the Ruby frontier. These hacks he’s posting are amazing. If there were a commercial for his blog, it’d show a kid chewing gum. Then a tidal wave. Then fruit syrup gushing through the kids mouth and jets of juice shooting out between his teeth like the dam’s gonna blow.

It does. Indigenous peoples die playing their bongos. Kids everywhere want their mouths to explode, too.

Take his xmp.rb, hacked in conspiracy with young and bright-futured and tumblicious and tumblelificent chris2. You feed this thing bunch of Ruby code and it annotates the code with output from the script, errors and warnings.

 RUBY_VERSION # => "1.8.3" 
 a = @a # !> instance variable @a not initialized
 class Foo
   def baz(n)
     (1..n).inject do |s,x|
       s + x   # => 3, 6, 10
     end
   end

   def bar(x)
     x.gsub(/foo/, "bar") # => "this is a bar", "this bar is bar" 
   end

   1+1 # => 2
 end

Look at the inject loop! It’ll print a joined list of values. Very tricky, Mauricio, you sly little man. I don’t know exactly how tall you are, Mauricio, but no one this conniving can be anyone other than the real Rumpelstiltzkin. Spinning code into gold. A gold purse for the rubies, how dare they glitter so brilliantly in mine eyes.

You know what would be wild? To use this as a way of writing test cases. You write the code that needs to be tested and annotate it with the asserts. (Also see Mauricio’s Changes in 1.9, a painstaking summary of what’s in Ruby’s HEAD right now.)

And now look what leprechaun has done just that with the unit testing idear. Blarney!

said on 23 Nov 2005 at 07:34

I quickly stole your idea and made a rough implementation

As for the tidal wave and Rumpelstiltzkin… that deserves further reflection. I will have to assess the numerous implications with great attention before I can answer meaningfully.

said on 23 Nov 2005 at 10:02

Where do I go to begin to understand this stuff?

said on 23 Nov 2005 at 11:40

RbyNby: Stay here and you’ll get the hang of it. I’ve also considered adding a beginner, medium, advanced level to posts like this. Would you find that helpful?

said on 23 Nov 2005 at 12:48

_why: you need faceted classification, like

rubyness: medium
whyhood: supreme
danger:     high
said on 23 Nov 2005 at 13:07

Oh, this, this is the good stuff.

said on 23 Nov 2005 at 13:32

RbyNby: Stare intently at the code and then let your eyes unfocus. Pretty soon you’ll see all kinds of interesting stuff in there. Then close your eyes and start coding like mad.

But seriously, keep hanging out here and you’ll be on the accelerated path to Ruby understanding. _why has a way of finding the good Ruby nuggets out there in Rubyblogdom and then he polishes them up to a high sheen and puts them in nice settings.

_why: I don’t think we need level tags. Beginners might shy away from an ‘advanced’ post when it could be just the thing they need.

said on 24 Nov 2005 at 01:25

I am also new to Ruby, but I read this site and several others religiously. While this hasn’t enhanced my sense of spiritual fulfillment, it has helped me begin to see the light reflecting from within the depths of the ruby.

Comments are closed for this entry.