View Single Post
  #1 (permalink)  
Old March 15th, 2007, 05:46 PM
ckonrad ckonrad is offline
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ruby on rails>>chomp

on p 17 of begining ruby on rails by holzner, he talks about how you cant use the chomp method with any other variable than the built $_ variable and goes on to demonstrate this very strange and convoluted code example:

print "Please enter the temperature: "
temperature = gets
$_ = temperature
chomp
temperature = $_
puts "The temperature is #{temperature}

That code above is just insane, one of the main points of ruby is making things simple

why not try this code instead

print "Please enter the temperature: "
puts "The temperature is #{gets.chomp}. This is after the chomp"

or to demonstrate that the author is in fact wrong about why he needed to create that convoluted code example why not do it like this

print "Please enter the temperature:"
temp = gets
puts "The temperature is #{temp.chomp}. this is after the chomp"

that works fine even though he says it shouldn't. I dont know if i want to use a book to learn something new from an author who makes a simple error like this, how many more errors are there in the book? who knows.