From: John Joyce Date: 2007-07-14T01:14:29+09:00 Subject: Re: gets On Jul 13, 2007, at 8:31 AM, Jeffrey Bowen wrote: > Thanks > Sometime I'm just slow. I tried > "test.chomp = gets" but I didn't try "test = > gets.chomp". The error message most likely told me > what was wrong. > > Thanks > Jeff > > --- Jeffrey Bowen wrote: > >> Of course the code below will not work because gets >> is >> adding /n to the entry. I know that chomp will >> remove >> the /n but is there away to cut the /n without >> reassigning test1 to another variable IE test2 = >> test1.comp >> >> print "test1 " >> test1 = gets >> puts test1.class >> if test1 == "1" >> puts "step 1" >> else >> puts "step 2" >> end >> >> Thanks >> Jeff >> test.chomp = gets and test = gets.chomp Will give you different results. test.chomp will return a chomped value but doesn't permanently chomp the value in test you would need to do test.chomp! = gets This is the destructive version of chomp, methods ending with ! usually modify the receiver in place, others usually don't. The reason my version doesn't need chomp! is because it takes the chomped value of gets and assigns that to test.