Answer the question
In order to leave comments, you need to log in
What is wrong with ruby?
Good afternoon! Started learning Ruby from Hal Fulton's tutorial. I'm trying to reproduce the code from the example, and, accordingly, parse it:
#!/usr/bin/ruby
#coding: utf-8
require 'colorize'
print "Введите температуру и шкалу (C or F):"
str = gets
exit if str.nil? or str.empty?
str.chomp!
temp, scale = str.split(" ")
abort "#{temp} недопустимое число." if temp !~ /-?/\d+/
temp = temp.to_f
case scale
when "C", "c"
f=1.8*temp + 32
when "F", "f"
c=(5.0/9.0) * (temp-32)
else
abort "Необходимо задать C или F\n"
end
if f.nil?
print "#{c} градусов C\n"
else
print "#{f} градусов F\n"
end
./begin.rb:10: syntax error, unexpected $undefined, expecting $end
... число." if temp !~ /-?/\d+/
... ^
# ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Answer the question
In order to leave comments, you need to log in
/-?/\d+/
Most likely after? / must not go. Why is he there?
I would update Ruby first. Anyway, in 2 years
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]he became smarter.
abort "#{temp} недопустимое число." if temp !~ /-?/\d+/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question