Ruby
Ruby Programming Language Topics









Subscribe to "Ruby" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.
 

 

Wednesday, July 30, 2003
 

There were several good discussions on c.l.r today.  First up is this one on Message-Object-Oriented compared to Function-Object-Oriented.  I was reading the originating article just the other day.  Anyway, the guy, James, that started the thread on c.l.r came up with a way to make Ruby syntax more like MOO.  It's ugly, but it shows how easy it is to manipulate Ruby.  Here's the magic:

I set about finding a way to do it in Ruby, and came up with an addition to the Symbol class. I wasn't sure if I wanted to have a full-blown Message class; I liked the idea that one could just type the message to send without having to go create a special object for it. The Symbol syntax makes this very natural

class Symbol
   def >>( *args )
     ary = []
     arglist  = (block_given? ? yield  : nil )
     args.each{ |obj|
       begin
        ary << dispatch( obj, arglist  )
       rescue Exception
        ary << $!.clone
       end
     }
     ary
   end

   def dispatch( obj, arglist  )
     return obj.send(self.to_s, *arglist) if arglist && (arglist.size>0)
     obj.send( self.to_s )
   end
end

This allows expressions like:

:some_message.>> obj
:some_message.>>( obj1, obj2 )
:some_message.>>( obj1, obj2 ){  [ arg1, arg2, arg3]  }

Any message string, instantiated as a Symbol, can be dispatched to a list of objects, along with a set of message arguments.  The results come back as an array.

The second thread is about implementing Ruby in Ruby.  This is the same idea demonstrated by creating a Lisp interpreter in Lisp.  Dan Sugalski (of Parrot fame) started an interesting thread.  See this for more along those lines.


9:41:50 PM    comment []


Click here to visit the Radio UserLand website. © Copyright 2004 Jon Israelson.
Last update: 3/17/04; 2:58:51 PM.
This theme is based on the SoundWaves (blue) Manila theme.
July 2003
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Jun   Aug