# Strange errors on Mac OS X

**URL:** <https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940>\
**Category:** Ruby\
**Created:** [December 3, 2007, 5:07am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940 "2007-12-03T05:07:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 3, 2007, 5:07am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/1 "2007-12-03T05:07:51Z")

</div>

I was wondering if anyone could help out a newbie in need. So I’ve just  
started learning Ruby, my first programming language. I’ve been going  
through this online book, and when running one of the programs from the  
book, I’ve been encountering a strange error. The program can be found  
here (it’s the one that writes numbers out in English), or you can check  
out the attachment, where I’ve included it:

[http://pine.fm/LearnToProgram/?Chapter=08](http://pine.fm/LearnToProgram/?Chapter=08)

I was running it unchanged from the website. I’ve tested it out on three  
computers, all Macs, but I always get this error:

numwrite.rb:1: syntax error  
# Now here- write\*100 # Subtract off those hundreds.ite  
out?ut.n’,  
^

The line of code it shows is gibberish, it seems to be made up of  
several lines of code mixed together. I’ve tested it on a Powerpc eMac  
running OS X 10.2 and Ruby 1.8.2, an Intel Macbook running 10.4 and Ruby  
1.8.6, and a Powerpc iBook running 10.4 and (I think) Ruby 1.8.4. All of  
these give me something similar to this error.  
Does anybody know what is going on, and can help, please?

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 3, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/2 "2007-12-03T13:45:26Z")

</div>

On 3 Dec, 04:07, “Gabriel N.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The line of code it shows is gibberish, it seems to be made up of  
> several lines of code mixed together.

Might be that your code is using carriage returns instead of linefeeds  
as end-of-line delimiters. Not sure about Ruby, but I know Python only  
recognises LFs as linebreaks. Prior to OS X, Mac OS used CRs as  
standard, and some Mac apps still do.

HTH

has

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 3, 2007, 5:32am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/3 "2007-12-03T05:32:39Z")

</div>

Hi Gabriel - I just copied and pasted your attachment and it ran  
without any issues on my laptop, a MacBook Intel Core Duo running OS X  
10.4.11 (bought nearly exactly one year ago). I ran it through two  
versions of Ruby, 1.8.4 and 1.8.6, both were fine.

It looks like something weird is going on, wish I could be more  
specific. There’s nothing wrong with the code that I can see.

–  
Giles B.

Podcast: [http://hollywoodgrit.blogspot.com](http://hollywoodgrit.blogspot.com)  
Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com](http://giles.tumblr.com)

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 3, 2007, 4:01pm UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/4 "2007-12-03T16:01:51Z")

</div>

On Dec 2, 9:07 pm, “Gabriel N.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> computers, all Macs, but I always get this error:  
> If you copy and paste text from a website, particularly when is has  
> been syntax colored and otherwise formatted, you can occasionally get  
> junk characters. (Most commonly, non-breaking spaces look like spaces  
> in your text editor but have a different ascii value, and confuse the  
> interpreter.)

Did you copy and paste the colored text from the website?

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 4, 2007, 12:01am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/5 "2007-12-04T00:01:42Z")

</div>

Gavin K. wrote:

> Did you copy and paste the colored text from the website?

Yes, yes I did. After seeing this, I tried copy-pasting a non-break  
space and using find/replace to replace them with normal spaces, but it  
seems as though the text editor doesn’t differentiate between non-break  
spaces and normal ones, as it was telling me that every space was a  
non-break space, even after I replaced them. I am still getting the  
error. This sounds plausible, though, are there any other characters  
that, coming from websites, break Ruby?

> Might be that your code is using carriage returns instead of linefeeds  
> as end-of-line delimiters. Not sure about Ruby, but I know Python only  
> recognises LFs as linebreaks. Prior to OS X, Mac OS used CRs as  
> standard, and some Mac apps still do.

I’ve been using Textedit, if that’s any help, in plain text mode. Though  
honestly, I have no clue what you’re talking about.

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 4, 2007, 12:21am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/6 "2007-12-04T00:21:25Z")

</div>

Just replace

def englishNumber number

with

def englishNumber(number)

… in this case Ruby shouldn’t care about LineFeeds and/or  
CarriageReturns.

Cheers  
Florian

Ruby with camelCase… yuck!

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 4, 2007, 1:42am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/7 "2007-12-04T01:42:03Z")

</div>

On Dec 3, 2007, at 6:44 AM, has wrote:

> On 3 Dec, 04:07, “Gabriel N.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > The line of code it shows is gibberish, it seems to be made up of  
> > several lines of code mixed together.
> 
> Might be that your code is using carriage returns instead of linefeeds  
> as end-of-line delimiters. Not sure about Ruby, but I know Python only  
> recognises LFs as linebreaks. Prior to OS X, Mac OS used CRs as  
> standard, and some Mac apps still do.  
> No mac apps use CR as line endings now. That went away with OS9’s  
> demise.  
> OS X and native apps all use Unix line endings as standard and as  
> defaults.  
> That means what you call LF, or line feed, or \n

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 4, 2007, 1:57am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/8 "2007-12-04T01:57:52Z")

</div>

> def englishNumber number
> 
> with
> 
> def englishNumber(number)
> 
> … in this case Ruby shouldn’t care about LineFeeds and/or CarriageReturns.

I thought that might be the issue, too, but it ran without my needing  
to edit that.

–  
Giles B.

Podcast: [http://hollywoodgrit.blogspot.com](http://hollywoodgrit.blogspot.com)  
Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com](http://giles.tumblr.com)

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 4, 2007, 7:50am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/9 "2007-12-04T07:50:22Z")

</div>

Try this. Go to the link you originally sent us:

[http://www.ruby-forum.com/attachment/1085/numwrite.rb](http://www.ruby-forum.com/attachment/1085/numwrite.rb)

Then click it with your mouse, select everything, and hit command-C to  
copy it.

Then open up TextMate, or vi, or whatever, save it, and see if that file  
runs.

That’s what I did, and it worked. If it doesn’t work for you, then  
there’s something crazy wiggy with your box. If it does work for you,  
then problem solved.

On 12/3/07, Gabriel N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## I had a friend running 10.5 and Ruby 1.8.6 try it out on his computer,
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Giles B.

Podcast: [http://hollywoodgrit.blogspot.com](http://hollywoodgrit.blogspot.com)  
Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com](http://giles.tumblr.com)

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 4, 2007, 3:40pm UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/10 "2007-12-04T15:40:44Z")

</div>

On 4 Dec, 00:36, John J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> No mac apps use CR as line endings now.

Some Carbon apps that date back to pre-OS X days still use CRs by  
default (I use one such app here, and its habit of changing my line  
endings is pretty annoying). Some modern text editors, e.g.  
TextWrangler, allow you to set the linebreak style along with other  
stuff like encodings.

The OP’s using TextEdit, which uses LFs by default, although I can’t  
recall if it preserves existing CRs in pasted text. Might be worth  
trying a better text editor to see if that unearths any hidden nasties

- e.g. TextWrangler costs nothing, can display hidden characters and  
lets you force line endings to the desired Unix style. And maybe take  
a look at [http://en.wikipedia.org/wiki/Newline](http://en.wikipedia.org/wiki/Newline) if still confused by  
my last attempt to explain linebreak issues.

HTH

has

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 8, 2007, 9:11pm UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/11 "2007-12-08T21:11:34Z")

</div>

Alright, thanks for helping me narrow it down. I managed to make it work  
by retyping the program myself rather than copy-pasting. I guess it was  
some “junk” character coming off the website that was confusing the  
interpreter. It’s working fine now, and I can get on with learning Ruby.  
A huge thank you to everyone who replied. 🙂

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 9, 2007, 3:09am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/12 "2007-12-09T03:09:18Z")

</div>

On Dec 8, 2007, at 3:11 PM, Gabriel N. wrote:

> Alright, thanks for helping me narrow it down. I managed to make it  
> work  
> by retyping the program myself rather than copy-pasting. I guess it  
> was  
> some “junk” character coming off the website that was confusing the  
> interpreter. It’s working fine now, and I can get on with learning  
> Ruby.  
> A huge thank you to everyone who replied. 🙂

You shouldn’t have had to retype by hand. Your code editor should be  
able to that for you. It should have a command like “Convert to  
ASCII” or “Zap Gremlins” or something similar. All the code editors  
that support Ruby that I am familiar with have such a command.  
TextWrangler, which is freeware, has both. Which editor are you using?

Regards, Morton

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 9, 2007, 11:07pm UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/13 "2007-12-09T23:07:26Z")

</div>

Morton G. wrote:

> Which editor are you using?

Textedit, in plain text mode, which isn’t really a code editor, but has  
been working fine for me so far. I assume it doesn’t have this feature.  
(I did do a search for “ASCII” in the help files, no match.)  
Unfortunately, the computers I’m using aren’t really mine, so I don’t  
want to load them with random software. I may download TextWrangler some  
time in the future though, after this mess.

---

<div class="post-metadata">

**Author:** ![rumpelstiltskin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rumpelstiltskin](https://www.ruby-forum.com/u/rumpelstiltskin)\
**Post date:** [December 4, 2007, 2:07am UTC](https://www.ruby-forum.com/t/strange-errors-on-mac-os-x/121940/14 "2007-12-04T02:07:33Z")

</div>

Florian AÃŸmann wrote:

> Just replace
> 
> def englishNumber number
> 
> with
> 
> def englishNumber(number)

Just tried it, it’s still giving me the error message.  
I had a friend running 10.5 and Ruby 1.8.6 try it out on his computer,  
and he got the error as well.  
His error gives a bit more detail though:

numwrite.rb:1: syntax error, unexpected kIF\_MOD, expecting ‘\n’ or ‘;’

# Now here- write\*100 # Subtract off those hundreds.ite out?ut.n’,

(Note: I deleted the little pointer (^) under the line because the app  
he used to send it to me removed all the spaces, making it uselessly  
point to the beginning of the line.)  
Hope that helps.
