# Small question about ruby -c

**URL:** <https://www.ruby-forum.com/t/small-question-about-ruby-c/49683>\
**Category:** Ruby\
**Created:** [December 7, 2005, 5:07pm UTC](https://www.ruby-forum.com/t/small-question-about-ruby-c/49683 "2005-12-07T17:07:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pat.eyler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/edb3f5/32.png) [@pat.eyler](https://www.ruby-forum.com/u/pat.eyler)\
**Post date:** [December 7, 2005, 5:07pm UTC](https://www.ruby-forum.com/t/small-question-about-ruby-c/49683/1 "2005-12-07T17:07:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pat.eyler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/edb3f5/32.png) [@pat.eyler](https://www.ruby-forum.com/u/pat.eyler)\
**Post date:** [December 7, 2005, 5:15pm UTC](https://www.ruby-forum.com/t/small-question-about-ruby-c/49683/2 "2005-12-07T17:15:21Z")

</div>

On 12/7/05, pat eyler [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![pat.eyler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/edb3f5/32.png) [@pat.eyler](https://www.ruby-forum.com/u/pat.eyler)\
**Post date:** [December 7, 2005, 5:15pm UTC](https://www.ruby-forum.com/t/small-question-about-ruby-c/49683/3 "2005-12-07T17:15:21Z")

</div>

pat eyler schrieb:

> ```
> 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

---

<div class="post-metadata">

**Author:** ![pat.eyler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/edb3f5/32.png) [@pat.eyler](https://www.ruby-forum.com/u/pat.eyler)\
**Post date:** [December 7, 2005, 6:53pm UTC](https://www.ruby-forum.com/t/small-question-about-ruby-c/49683/4 "2005-12-07T18:53:18Z")

</div>

Quoting pat eyler [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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?

Basically, it’s not a syntax error. It’s possible for a script to  
be wrong in surprising ways but still syntactically valid.

-mental
