Ruby/Development/chomp

Материал из Wiki.crossplatform.ru

Версия от 17:55, 13 сентября 2010; ViGOur (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Ruby method chomp removes that newline character from the end of the text in the $_ variable.

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



you don"t need to use $_ with gets - you can assign the text it reads to any variable: temperature = gets

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