Recent Comments

Ruby

Ruby is a general purpose interpreted object oriented language popular for building websites (search Google for “Ruby on Rails”).  It is similar to Python and Perl.

Download software: http://rubyinstaller.org (Windows)

Cost: Free

Instructions to setup software: See Ruby installer at http://rubyinstaller.org

Hardware requirements: PC, Mac

Operating systems supported: Win, Mac, Linux

Difficulty level: 3 out of 5


TRY IT!

1. Copy this text, paste into notepad (or some other text editor) and save as “TempF_to_C.rb”


def getFTemp
	print "Enter Temperature Degrees F :"
	tempF = gets()
	tempC = (tempF.to_f - 32)*5/9
	puts "Temperature Degrees C: #{tempC}"
	return tempF
end

def useTemp (temp)
	if (temp.to_f > 100)
		print "Hydrate!!"
	end
	if (temp.to_f <32)
		print "Pack Long Underwear!!"
	end
end

begin
	Ftemp = getFTemp
	useTemp(Ftemp)
end

2. From the command prompt, type: “Ruby200\bin\ruby.exe TempF_to_C.rb”

Here is a sample session:

ruby


ABOUT THE PROGRAM — A WALK THROUGH

The program starts at the “begin” near the bottom.

It uses the “getFTemp” method to prompt the user and convert the temperature to Degrees C.

It then uses the “useTemp” method to decide which message to display.


TRY THIS

1. Modify “useTemp” to display a message for temperatures between 32 and 100.

2. Change the messages that are displayed.

3. Change the temperatures that trip the message displays.


LEARN MORE

Programming Ruby – an excellent on line book

Ruby in Twenty Minutes


RESOURCES, TIPS, TRICKS AND HINTS

http://www.ruby-lang.org

2 Comments on Ruby

  1. Ruby was confusing at first, but now it is very easy

Leave a Comment

Please don't use your real name.