|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I was wondering if anyone could 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 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 , please? Attachments: http://www.ruby-forum.com/attachment/1085/numwrite.rb -- Posted via http://www.ruby-forum.com/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com On 12/2/07, Gabriel N. <gabrielbn@hotmail.com> wrote: > I was wondering if anyone could 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 > > 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 , please? > > Attachments: > http://www.ruby-forum.com/attachment/1085/numwrite.rb > > -- > Posted via http://www.ruby-forum.com/. > > |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 3 Dec, 04:07, "Gabriel N." <gabrie...@hotmail.com> 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 -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Dec 2, 9:07 pm, "Gabriel N." <gabrie...@hotmail.com> wrote:
> I was wondering if anyone could 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 > > I was running it unchanged from the website. I've tested it out on three > 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? |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Gavin Kistner 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 , in plain text mode. Though honestly, I have no clue what you're talking about. -- Posted via http://www.ruby-forum.com/. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Just replace
def englishNumber number with def englishNumber(number) =2E.. in this case Ruby shouldn't care about LineFeeds and/or CarriageRet= urns. Cheers Florian Ruby with camelCase... yuck! |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Dec 3, 2007, at 6:44 AM, has wrote: > On 3 Dec, 04:07, "Gabriel N." <gabrie...@hotmail.com> 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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
> 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 Bowkett Podcast: http://hollywoodgrit.blogspot.com Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com |
|
![]() |
| Outils de la discussion | |
|
|