From: Devin Mullins Date: 2006-12-31T06:00:28+09:00 Subject: Re: Newbie: It works, how can I make it better? William James wrote: > def convert( from, to, func ) > print "Enter a temperature in #{from}: " > temp = gets.to_f > puts "#{temp} #{from} is #{func[temp].round} #{to}." > end > > case gets.to_i > when 1 > convert( "F", "C", proc{|f| (f - 32) / 1.8 } ) > when 2 > convert( "C", "F", proc{|f| f * 1.8 + 32 } ) > else > puts "That is a not a valid choice. Good bye!" > end Err... why not make it a block? def convert( from, to ) print "Enter a temperature in #{from}: " temp = gets.to_f puts "#{temp} #{from} is #{yield(temp).round} #{to}." end case gets.to_i when 1 convert( "F", "C") {|f| (f - 32) / 1.8 } when 2 convert( "C", "F") {|f| f * 1.8 + 32 } else puts "That is a not a valid choice. Good bye!" end Also, check out http://highline.rubyforge.org/ for your prompting needs. Devin