From: Philipp Hofmann Date: 2008-03-03T13:05:40+09:00 Subject: Re: [QUIZ] Hello, world? (#158) # i -- raising an HelloWorldError class HelloWorldError < StandardError def to_s "Hello, World!" end end module Kernel def raise(e) puts e end end raise HelloWorldError.new # ii -- a lost and found HelloWorld class HelloWorld def to_s "Hello, World!" end end HelloWorld.new ObjectSpace.each_object { |o| puts o if o.is_a?(HelloWorld) } # iii -- a little curry hello = lambda { |a| "Hello, #{a.call}"} world = lambda { "World!" } puts hello.call(world) # iv -- in only one line but to ruby instances puts `ruby -e 'puts "Hello, World!"'` # v -- and finally a probabilistic approach # beware this one is not tested yet! # which means the the test is still running and at # least it didn't raise any errors so far ;) goal = "Hello, World!\n" bytes = goal.split(//).map { |e| e[0] }.uniq seed = 0 until false srand(seed) i = 0 while i < goal.size c = rand(bytes.size) break if bytes[c] != goal[i] i += 1 end break if i == goal.size seed += 1 end goal.size.times { print bytes[rand(bytes.size)].chr } g phil