[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

void value expression

Peter Vanderhaden

11/17/2007 8:58:00 AM

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
--
Posted via http://www.ruby-....

2 Answers

Sebastian Hungerecker

11/17/2007 9:12:00 AM

0

Peter Vanderhaden wrote:
> =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: sepp2k@jabber.org
ICQ: 205544826

Peter Vanderhaden

11/17/2007 9:26:00 AM

0

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

Sebastian Hungerecker wrote:
> Peter Vanderhaden wrote:
>> 48 @in_file.each |record_line|
> ^^
> @in_file.each do |record_line|
>
>
> HTH,
> Sebastian

--
Posted via http://www.ruby-....