Wednesday, June 22, 2005
MOO, Ruby
I have long held a special place in my heart for the programming language known as MOO Code. Developed by Pavel Curtis at Xerox's Palo Alto Research Centre, MOO was a language far ahead of its time -- but sadly restricted by having to be hosted within in its own server.
On a MOO I frequented, MOO Canada Eh?, one of the tests to become a programmer was to explain what the following chunk of code did [1]:
This code illustrates much of why I loved that language -- so flexible, so terse, so delicious! In the PickAxe, I have come across an absolute gem of Ruby code [2]:
[1] Code to allow would-be targets to duck pies thrown at them by villanous MOOers.
[2] Code to implement dynamic method-result caching in Ruby by invisibly altering the method table.
On a MOO I frequented, MOO Canada Eh?, one of the tests to become a programmer was to explain what the following chunk of code did [1]:
#3127:"duck" this none none
1: $msg:mtell(d = {args[1], player}[(iobj != args[1]) + 1], "duck_" + {"successful", "failed"}[((g = this.gonna_get_pied) == (this.gonna_get_pied = setremove(g, d))) + 1], this.owner:title(), d)
This code illustrates much of why I loved that language -- so flexible, so terse, so delicious! In the PickAxe, I have come across an absolute gem of Ruby code [2]:
I think I'm going to love this language.
def once(*ids) # :nodoc:
for id in ids
module_eval <<-"end;"
alias_method :__#{id.to_i}__, :#{id.to_s}
private :__#{id.to_i}__
def #{id.to_s}(*args, &block)
(@__#{id.to_i}__ ||= [__#{id.to_i}__(*args, &block)])[0]
end
end;
end
end
[1] Code to allow would-be targets to duck pies thrown at them by villanous MOOers.
[2] Code to implement dynamic method-result caching in Ruby by invisibly altering the method table.