LSRC Name Picker

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.

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

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

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.

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