LSRC Name Picker

A

Ari Brown

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],
:eek:pt_description => "Prints this page."
)
o << Option.new:)names => %w[--file -f],
:arg_arity => [1,1],
:arg_description => "file",
:eek:pt_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.
 
A

Alex Gutteridge

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:

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 Gutteridge

Bioinformatics Center
Kyoto University
 
J

James Edward Gray II

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?

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 Gray II
 
A

Ari Brown

On Jul 3, 2007, at 8:55 AM, James Edward Gray 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 Gray II

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

James Edward Gray II

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

I was trying this:
@names =3D open('.names.txt', 'w+')
in initialize, and then write to that file later on. Is there a =20
better way to do this?

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

@names.puts "=85"

James Edward Gray II=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top