teaching machines

CS 330 Lecture 4 – Ruby

February 2, 2015 by . Filed under cs330, lectures, spring 2015.

Agenda

TODO

Perry’s Stages of Cognitive Development

Code

aspect.rb

#!/usr/bin/env ruby

print 'Width: '
width = gets.to_f
print 'Height: '
height = gets.to_f

aspect_ratio = width / height
puts "Aspect ratio: #{aspect_ratio}"

spacer.rb

#!/usr/bin/env ruby

puts ARGV

sum = 0
# for i in 0...ARGV.size 
  # sum += File.stat(ARGV[i]).size 
# end 

ARGV.each do |item|
  sum += File.stat(item).size
end

puts sum

rhymes.rb

#!/usr/bin/env ruby

require 'open-uri'
require 'json'

json = open("http://rhymebrain.com/talk?function=getRhymes&word=#{ARGV[0]}").read
rhymes = JSON.parse(json)

rhymes.each do |rhyme|
  puts rhyme['word']
end

Haiku

on Perryian commitment
He is not the one
But I will still marry him
And then he will be