From: Jesse Merriman Date: 2008-03-03T09:20:08+09:00 Subject: [SOLUTION][QUIZ] Hello, world? (#158) Here's 6 little solutions (pastied http://pastie.caboo.se/160330 too). The last two just print the file name, so they'll have to be in a "Hello, world!" file (or as close as your OS supports). ## attempt 1 def print_caller print caller.first.match(/`(.*)'$/)[1] end def H; print_caller; end def e; print_caller; end def l; print_caller; end def o; print_caller; end def comma; print ','; end def space; print ' '; end def w; print_caller; end def r; print_caller; end def d!; print_caller; end def newline; print "\n"; end H(); e; l; l; o; comma; space; w; o; r; l; d!; newline ## attempt 2 class Hello def self.printer s; define_method(s) { print s; self }; end %w{H e l o w r d!}.each { |s| printer(s) } end Hello.new.H.e.l.l.o.w.o.r.l.d! ## attempt 3 class Hello def method_missing m; print m; self; end end Hello.new.H.e.l.l.o.send(', ').w.o.r.l.d!.send("\n") ## attempt 4, quine-ish #!/usr/bin/env ruby require 'enumerator' lines = File.readlines(__FILE__) [20, 0, 0, 11, 4, 0, 4, 0, 2, 17, 5, 3, 0, 14, 18, 28, 2, 17, 0, 5, 4, 0, 4, 16, 0, 1, 1, 0].each_slice(2) { |row, col| print lines[row][col..col] } Hash ## attempt 5 # Must be in a file called "Hello, world!" begin raise :foo rescue StandardError => se puts se.backtrace.first.match(/([^\/\\:]+):/)[1] end ## attempt 6 # Must be in a file called "Hello, world!" puts __FILE__