From: Matthew D Moss Date: 2008-03-01T09:06:05+09:00 Subject: [QUIZ] Hello, world? (#158) The three rules of Ruby Quiz 2: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have passed from the time on this message. 2. Support Ruby Quiz 2 by submitting ideas as often as you can! (A permanent, new website is in the works for Ruby Quiz 2. Until then, please visit the temporary website at . 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Hello, world? The first program any new programmer typically sees is one that prints out "Hello, world!" to the console. This tends to be something experienced programmers also see when learning a new language. The first Hello World program was written in B [1] by Kernighan and looked like this: main( ) { extrn a, b, c; putchar(a); putchar(b); putchar(c); putchar('!*n'); } a 'hell'; b 'o, w'; c 'orld'; Most programmers are probably more familiar with the typical C implementation: main() { printf("Hello, world!\n"); } Ruby can present the same output very simply: puts "Hello, world!" But that's too simple... I mean, really... *anyone* can print a simple string to standard output. Can't we get more interesting? Hmmm, how about: puts sprintf("%s, %s!", "Hello", "world") Eh, that looks too much like C. Maybe... puts %w(Hello world).join(", ") + "!" Yeah, that's definitely looking Ruby-ish. Your task this week is to print "Hello, world!" to standard output using Ruby in atypical fashion. Some guildlines: - DO submit multiple variants in your submission, but we don't need 100 variants from everyone. Try to limit yourself to your best dozen. - DO keep things reasonably simple. I would expect many solutions to be one- or two-liners, some solutions to involve classes and functions, and a variety in-between. But we're looking for Ruby-isms, not volume of code, so don't write pages upon pages of code just to print "Hello, world!" - DON'T obfuscate unnecessarily. We're looking for interesting Ruby tricks, not utter confusion. A little obfuscation is okay, but a lot is to be avoided. - DON'T send me my own examples from above. I already did them. Do other stuff. It *is* okay if your solution is similar to mine, provided you make some interesting modifications. [1] http://cm.bell-labs.com/cm/cs/who/dmr/btut.html