Exercise: rectangle

examples/ruby/rectangle.rb

width = 23
length = 19

area = width * length
circumference = 2 * (width + length)
puts "area: #{area}"
puts "circumference: #{circumference}"

examples/ruby/rectangle_cli.rb

if ARGV.size != 2
    puts "#{$PROGRAM_NAME} WIDTH LENGTH"
    exit 1
end

width = ARGV[0].to_f
length = ARGV[1].to_f

area = width * length
circumference = 2 * (width + length)
puts "area: #{area}"
puts "circumference: #{circumference}"

examples/ruby/rectangle_stdin.rb

print "Width:"
width = gets.strip.to_f

print "Length:"
length = gets.strip.to_f

area = width * length
circumference = 2 * (width + length)
puts "area: #{area}"
puts "circumference: #{circumference}"