Hello, world? (#158)

Forwarded solution from Paolo Bonzini:

···

Date: March 2, 2008 8:26:21 AM EST
Subject: Re: Hello, world? (#158)

Hi, I write privately because when the 48 hours have passed I'll
probably be asleep. Here's my solution, inspired by the recent thread
on monkeypatching. It makes all messages printed more happy and
interesting by capitalizing them and adding an exclamation mark at the
end.

It's a pity that Kernel#puts reimplements $stdout.puts instead of just
delegating it. Of course, I fixed that with another monkeypatch.

class IO
  alias_method :orig_puts, :puts
  def puts *args
    args = [""] if args.length == 0
    args.each do |x|
      if x.class == Array
        puts *x
      else
        x = x.gsub(/[^!]$/) { |final| final + "!" }
        x = x.gsub(/\w+/) { |w| w.capitalize }
        orig_puts x
      end
    end
  end
end

class << self
  def puts *args
    $stdout.puts *args
  end
end

puts "hello, world"