# LSRC Name Picker

**URL:** <https://www.ruby-forum.com/t/lsrc-name-picker/108411>\
**Category:** Ruby\
**Created:** [July 3, 2007, 9:08am UTC](https://www.ruby-forum.com/t/lsrc-name-picker/108411 "2007-07-03T09:08:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 3, 2007, 9:08am UTC](https://www.ruby-forum.com/t/lsrc-name-picker/108411/1 "2007-07-03T09:08:19Z")

</div>

Hey all.  
I seem to get this error whenever I run my program.

-----------------------------------------------------------|  
ERROR  
-----------------------------------------------------------|  
namePicker-cli.rb:58: syntax error, unexpected ‘{’, expecting kEND  
@names { |f| lines = f.readlines  
^  
namePicker-cli.rb:60: syntax error, unexpected ‘}’, expecting kEND  
-----------------------------------------------------------|  
What does this mean? Here is my code:

-----------------------------------------------------------|  
CODE  
-----------------------------------------------------------|  
###########################################

# Tally ho, I’m going to write this

# as best I can. Store the picked names

# to a file, and then that will be the checker.

###########################################

require ‘ftools’  
require ‘rubygems’  
require ‘commandline/optionparser’  
include CommandLine

##############################

# Set us up for CL options

##############################  
od = OptionParser.new { |o|  
o \<\< Option.new(:flag,  
:names =\> %w[–help -h],  
:opt\_description =\> “Prints this page.”  
)  
o \<\< Option.new(:names =\> %w[–file -f],  
:arg\_arity =\> [1,1],  
:arg\_description =\> “file”,  
:opt\_found =\> OptionParser::GET\_ARGS  
)  
}

op = od.parse

######################

# Set up some rules

######################  
if op[’–help’]  
puts od  
exit()  
end

#################

# Variables…

#################  
FILE = op[’–file’]

#####################

# NamePicker Class

#####################  
class NamePicker

def initialize  
# names = open(FILE)  
File.syscopy(FILE, ‘.names.txt’)  
@names = open(’.names.txt’, ‘w+’)  
end

def random  
selected = nil  
@names.inject { |choice, line| selected \< 1/quiz.lineno.to\_f ?  
line : choice }  
if selected  
puts selected.chomp  
@names { |f| lines = f.readlines

### LINE 58

```
     lines.puts unless $. == selected.chomp
   }
                   ### LINE 60
   self.rewind
 end

```

end  
end

randomName = NamePicker.new  
randomName.random  
#end

Suggestions? Any?  
~ Ari  
English is like a pseudo-random number generator - there are a  
bajillion rules to it, but nobody cares.

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 3, 2007, 10:21am UTC](https://www.ruby-forum.com/t/lsrc-name-picker/108411/2 "2007-07-03T10:21:33Z")

</div>

On 3 Jul 2007, at 16:07, Ari B. wrote:

> -----------------------------------------------------------|  
> What does this mean? Here is my code:

snip

> ```
> @names { |f| lines =  
> 
> ```
> 
> f.readlines ### LINE 58  
> lines.puts unless $. == selected.chomp  
> }  
> ### LINE 60

Untested, but shouldn’t this be

```
 @names.each{ |f| lines =

```

f.readlines ### LINE 58  
lines.puts unless $. == selected.chomp  
}

Alex G.

Bioinformatics Center  
Kyoto University

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 3, 2007, 2:57pm UTC](https://www.ruby-forum.com/t/lsrc-name-picker/108411/3 "2007-07-03T14:57:17Z")

</div>

On Jul 3, 2007, at 2:07 AM, Ari B. wrote:

> What does this mean?  
> It’s Ruby’s way of telling you that your code doesn’t make sense.

Basically, you are defining a block for an instance variable here,  
but only methods can take blocks in Ruby. I assume you meant to call  
some iterator and forgot to include the method name.

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 3, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/lsrc-name-picker/108411/4 "2007-07-03T15:02:18Z")

</div>

On Jul 3, 2007, at 8:55 AM, James Edward G. II wrote:

> It’s Ruby’s way of telling you that your code doesn’t make sense.
> 
> Basically, you are defining a block for an instance variable here,  
> but only methods can take blocks in Ruby. I assume you meant to  
> call some iterator and forgot to include the method name.  
> I was trying this:  
> @names = open(’.names.txt’, ‘w+’)  
> in initialize, and then write to that file later on. Is there a  
> better way to do this?

> Hope that helps.  
> It did!  
> James Edward G. II

Ari  
--------------------------------------------|  
If you’re not living on the edge,  
then you’re just wasting space.

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [July 3, 2007, 3:10pm UTC](https://www.ruby-forum.com/t/lsrc-name-picker/108411/5 "2007-07-03T15:10:20Z")

</div>

On Jul 3, 2007, at 8:00 AM, Ari B. wrote:

> @names = open(’.names.txt’, ‘w+’)  
> in initialize, and then write to that file later on. Is there a  
> better way to do this?

This is fine and in that case you don’t need the block at all. You  
can just write to the file with:

@names.puts “…”

James Edward G. II
