Posted by matijs 14/10/2007 at 12h14
In Ruby, there is really no compile time. There is parse time, and then there is run time. All class and method definitions are done at run time.
class Foo def bar puts “Zoo!” end end
Foo = Class.new do self.define_method(:bar) do puts “Zoo!” end end
See, we just removed the class and def keywords from Ruby. What else? Ah yes, method calls. That’s just sending messages. In fact, you can replace any method call
foo.send(:bar), like so2:
Foo = Class.send(:new) do self.send(:define_method, :bar) do self.send(:puts, “Zoo!”) end end
How much syntax can you remove like this? How far can Ruby be undressed? And can you come up with a macro system to put the clothes back on?
2 Yes, I know I’m using method call syntax here. But this way I do expose the message-passing view on OO that Ruby has. If you want, you can replace it with
send_message(object, method, *args), and assume Ruby defines