From: Rob Biedenharn Date: 2010-07-13T20:43:11+09:00 Subject: Re: Why do I get undefined method? On Jul 13, 2010, at 6:16 AM, Abder-Rahman Ali wrote: > Thanks for your replies. I changed the script to look as follows: > http://pastie.org/private/qwcmcpdzvxybm52s3ywxqg > > But, I ALWAYS get "Out of range...". Why is that? > > Thanks. > > def what_were_you_doing_on (year) > if (2001..2006).include?(year) > puts "BSc" > elsif (2007..2009).include?(year) > puts "MSc" > else > puts "Out of range..." > end > end > > puts "Enter year " > year = gets > what_were_you_doing_on (year) Because gets returns a string (which will still have a newline). So you're asking: (2001..2006).include?("2003\n") Try: year = gets.to_i -Rob Rob Biedenharn Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/ rab@GaslightSoftware.com http://GaslightSoftware.com/