small question about ruby -c

P

pat eyler

interesting little bug (I think)

When generating the answer to a previous email, I ran ruby -c against
a script and got 'syntax ok'. (as expected) I then changed an
if/else/end to if/otherwise/end, ran ruby -c again, and got 'syntax
ok'. (not as expected). I went ahead and ran the script (with the
'otherwise' change) and got:

-- primes_with_error.rb:29: undefined local variable or method
`otherwise' for main:Object (NameError)
from primes_with_error.rb:25:in `each'
from primes_with_error.rb:25


Any reason that ruby -c didn't catch this?


thanks,
-pate
-------------------------
 
P

Patrick Hurley

When generating the answer to a previous email, I ran ruby -c against
a script and got 'syntax ok'. (as expected) I then changed an
if/else/end to if/otherwise/end, ran ruby -c again, and got 'syntax
ok'. (not as expected).

I can't see your code, but my guess is that the ruby interpreter
figured that otherwise is a function (not an accidental name for
else), so it is good syntax, even though there is a runtime error for
the missing method/variable name.

pth
 
P

Pit Capitain

pat said:
interesting little bug (I think)

When generating the answer to a previous email, I ran ruby -c against
a script and got 'syntax ok'. (as expected) I then changed an
if/else/end to if/otherwise/end, ran ruby -c again, and got 'syntax
ok'. (not as expected). I went ahead and ran the script (with the
'otherwise' change) and got:

-- primes_with_error.rb:29: undefined local variable or method
`otherwise' for main:Object (NameError)
from primes_with_error.rb:25:in `each'
from primes_with_error.rb:25

Any reason that ruby -c didn't catch this?

Pat, this isn't a syntax error. The *syntax* is correct. Just define a
method or local variable named "otherwise" and all is fine.

Regards,
Pit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,199
Messages
2,571,045
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top