# Trying to write a first plain ruby script

**URL:** <https://www.ruby-forum.com/t/trying-to-write-a-first-plain-ruby-script/142774>\
**Category:** Ruby\
**Created:** [July 11, 2008, 10:10am UTC](https://www.ruby-forum.com/t/trying-to-write-a-first-plain-ruby-script/142774 "2008-07-11T10:10:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 11, 2008, 10:10am UTC](https://www.ruby-forum.com/t/trying-to-write-a-first-plain-ruby-script/142774/1 "2008-07-11T10:10:01Z")

</div>

In irb, the method “one\ntwo\nthree”.split worked fine

## but in a file…

@text = "

line one  
line two  
line three  
"

## @lines = @text.split(/\n/)

… it fails: “private method `split’ called for nil:NilClass  
(NoMethodError)”

After getting the array of lines, again I need to call split() on each  
line, then joing them with ", "

(basically I need a CSV file for 14,000 lines verb annotation from  
WordNet)

It’s late, so I probably could not figure this out myself tonight. Any  
help is welcome. Thank you.

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 11, 2008, 12:08pm UTC](https://www.ruby-forum.com/t/trying-to-write-a-first-plain-ruby-script/142774/2 "2008-07-11T12:08:22Z")

</div>

-------- Original-Nachricht --------

> Datum: Fri, 11 Jul 2008 17:05:54 +0900  
> Von: Jesse C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: Trying to write a first plain ruby script

> WordNet)
> 
> ## It’s late, so I probably could not figure this out myself tonight. Any help is welcome. Thank you.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Dear Jesse,

I cannot reproduce your error on Ubuntu Linux … did you really post  
the exact text/code ?  
What operating system are you working on ? I suspect that the line  
breaks might be \r\n instead  
of just \n (especially if the text file was created on Windows), and  
that

@lines = @text.split(/\n|\r\n/)

would work.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 11, 2008, 7:08pm UTC](https://www.ruby-forum.com/t/trying-to-write-a-first-plain-ruby-script/142774/3 "2008-07-11T19:08:10Z")

</div>

Heh. It was even later than I thought. The problem was that I called  
the text string “@index\_verbs” and had been trying to call `split’ on  
“@verb\_index”

I can probably accomplish the rest of the script today 🙂
