From: Morton Goldberg Date: 2008-03-03T11:28:09+09:00 Subject: Re: [QUIZ] Hello, world? (#158) [SOLUTION] To me, the essence of a "hello, world" program is to get the phase on the computer screen. But "on the screen" doesn't have to mean "write to stdout". My three solutions all avoid stdout. The first solution highjacks Apple's TextEdit application. require "appscript" include Appscript te = app('TextEdit') te.launch te.documents.end.make(:new => :document, :with_properties => {:text => "hello, world\n"}) The second solution uses an AppleScript dialog. require "osax" include OSAX osax.display_dialog("hello, world") These first two solutions are Apple-centric. I don't apologize for that. I also employed the classic Kernighan and Ritchie version, just "hello, world", no caps or exclamation point. The third solution uses Tk and should run on any system with a functioning Ruby/Tk library, but you may have to specify another font. This one is not so minimalist as the first two. Here I use what today seems to be the most common version of the phrase ("Hello, World!") just because it looks prettier in 72-point Brush Script. require 'tk' root = Tk.root root.title('Ruby/Tk Hello') win_w, win_h = 360, 160 win_x = (root.winfo_screenwidth - win_w) / 2 root.geometry("#{win_w}x#{win_h}+#{win_x}+50") root.resizable(false, false) TkLabel.new(root) { text 'Hello, World!' relief 'solid' borderwidth 1 font('family'=>'Brush Script MT', 'size'=>72) place("x"=>10, "y"=>10, "height"=>92, "width"=>340) } TkButton.new(root) { text 'Goodbye' command { Tk.root.destroy } place("x"=>138, "y"=>122, "height"=>28, "width"=>83) } Tk.mainloop The use of 'place', rather than 'pack' may seem strange. I confess I wrote the Ruby/Tk version quite some time ago when I was experimenting with the 'place' layout manager. Regards, Morton