void value expression

P

Peter Vanderhaden

I'm a Ruby & OO newbie, so please bear with me. I wrote a Ruby script
that works, but it is written in a "procedural" way as opposed to OO.
I'm now trying to convert it to OO principles, but am having a tough
time. I'm getting the following error when I run the program. Can
anyone give me an idea of what might be the problem? (I know that some
methods only contain placeholder comments, but I don't think that should
be the cause of the problem.) Any help is really appreciated!

1 #!/usr/bin/ruby
2 class Record
3 def initialize (record_string)
4 @record = record_string
5 end
6
7 def fix_volume_label
8 # TODO: apply processing to @record to fix volume label
9 # if required for this record
10 end
11
12 def fix_extension_case
13 # TODO: apply processing to @record to fix volume file
extension
14 # case if required for this record
15 end
16
17 def to_str
18 @record
19 end
20
21 end
22
23 class FixOpt
24 def initialize
25
26 @argv = $*
27 @header_regex = /BegBates,Volume,Path/
28 @in_file = nil
29 @out_file = nil
30
31 unless arguments_valid? @argv
32 usage
33 exit -1
34 end
35
36 begin
37 @in_file.open argv[0]
38 rescue IOError
39 @in_file.close
40 puts "error opening input file, terminating"
41 exit -1
42 end
43
44 end
45
46 def run
47 begin
48 @in_file.each |record_line|
49 next if record_line =~ @header_regex
50 record = Record.new(line)
51 record.fix_volume_label
52 record.fix_extension_case
53 puts record #same as puts record.to_str
54 end
55 rescue IOError
56 @in_file.close
57 puts "error reading from input file, terminating"
58 exit -1
59 end
60 @in_file.close
61 exit 0
62 end
63
64 :private
65
66 def arguments_valid? (argv)
67 # validate argv[0] is a file and we have permission to open
68 end
69
70 def usage
71 # print usage
72 end
73
74 #end
75
76 fix_opt = FixOpt.new
77 fix_opt.run
 
S

Sebastian Hungerecker

Peter said:
=C2=A048 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 @in_file.each |record_=
line|
^^
@in_file.each do |record_line|


HTH,
Sebastian
=2D-=20
Jabber: (e-mail address removed)
ICQ: 205544826
 
P

Peter Vanderhaden

Sebastian,
Thank you so much! Believe it or not, I had noticed the missing do when
I left the office about 12 hours ago, but forgot about it when I got
home. Another pair of eyes this late sure helps!
PETERV
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top