From: Nola Stowe Date: 2006-02-27T00:39:43+09:00 Subject: Re: [QUIZ] Current Temperature (#68) hahaha, thats great. Very entertaining Dave. Sometimes I wish I was that funny :) On 2/26/06, Dave Burt wrote: > Ruby Quiz wrote: > > Write a Ruby program such that given a certain argument to the program it > > will return the current temperature of that location. > > I still haven't done last week's metakoans, but I thought to myself, "Dave," > (because I always address myself by name in my thoughts). "Dave," I thought, > "a universal Ruby-based indicator of the current temperature that works in > any location on any Ruby platform would be a great boon not only to you, but > to the entire Ruby community. In fact, why stop at the temperature? Ruby has > the power to turn almost any device into a fully functional weather station, > measuring rain, wind and snow. The world will be amazed." > > So, thinking of you all, I wrote the code I now humbly present. > > Cheers, > Dave. > > #!/usr/bin/ruby > # > # Current Weather > # > # A response to Ruby Quiz #68 [ruby-talk:181420] > # > # This script basically turns your Ruby device into a weather machine. It > # leverages the latest technology to enable most laptops, PDAs, etc. to > capture > # meterorological metrics. > # > # WARNING: this program has a bug resulting in an infinite loop on > non-portable > # platforms. > # > # Please ONLY EXECUTE THIS PROGRAM ON PORTABLE DEVICES. > # > # Author: Dave Burt > # > # Created: 23 Oct 2005 > # > > require 'highline/import' > > # Work around bug > agree("Are you using a portable Ruby device? ") or > abort("Sorry, this program has not yet been ported to your platform.") > > # Calibrate instrumentation > begin > say "Go outside." > end until agree("Are you outside now? ") > > # Ascertain cloud cover > if agree("Is your Ruby device casting a defined shadow? ") > say "It's sunny." > else > say "It's overcast." > end > > # Capture rainfall > if agree("Are your Ruby device or your umbrella wet? ") > say "It's raining." > else > say "It's fine." > end > > # Weigh other precipitation > if agree("Is your Ruby device becoming white? ") > say "It's snowing." > else > say "It's not snowing." > end > > # Discern current temperature > if agree("Are your fingers getting cold? ") > say "It's cold." > else > say "It's warm." > end > > # Measure wind speed > if agree("Do you feel lateral forces on your Ruby device? ") > say "It's windy." > else > say "It's calm." > end > > say "This weather report has been brought to you by Ruby, the letter D," > say "and the number 42." > > > > -- http://PhpGirl.blogger.com http://CodeSnipers.com