I
I
Ivan Kiselev2014-10-13 11:59:51
ruby
Ivan Kiselev, 2014-10-13 11:59:51

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

I am getting the following error:
./begin.rb:10: syntax error, unexpected $undefined, expecting $end
... число."  if temp !~ /-?/\d+/
...                               ^

Asking for help and waiting for answers in the style of "LEARN THE MATTER, NUB [link]"
I understand that the interpreter will most likely give me enough information for analysis if I had any experience in ruby, however at the current moment, I don’t have the opportunity to understand what is the error in the program that I copied and pasted, since I have never been able to run it if it contains a piece of code on which everything falls down.
ruby version:
# 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

3 answer(s)
A
Artur Bordenyuk, 2014-10-13
@homelessness

/-?/\d+/
Most likely after? / must not go. Why is he there?

W
webbus, 2014-10-13
@webus

I would update Ruby first. Anyway, in 2 years

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
he became smarter.

A
Alexander Maslov, 2014-10-13
@drakmail

abort "#{temp} недопустимое число."  if temp !~ /-?/\d+/

Must be !=~

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question