Tuesday, January 6, 2009

I heart Ruby

Here is another reason why I love Ruby:
?> module Sweatshirt
>> def self.included(klass)
>> klass.extend ClassMethods
>> end
>>
?> module ClassMethods
>> def read_aloud
>> "Now I have a machine gun"
>> end
>> end
>> def read_aloud
>> "ho, ho, ho"
>> end
>> end
=> nil
>>
?> class DieHard
>> include Sweatshirt
>> end
=> DieHard
>>
?> puts "#{DieHard.read_aloud} #{DieHard.new.read_aloud}"
Now I have a machine gun ho, ho, ho
=> nil

No comments: