Problem with files comparing

C

Cheyne Li

Hi, there

My problem is to compare two files in the same directory as the program
does.

the code is:

require 'ftools'
def fcmp
from = 'my_log.txt'
to = 'my_log_e.txt'
if compare(from,to, verbose = false) then
puts 'Identical.'
else
puts 'Different.'
end
end

After running the function. There's no result as all. Is there anybody
has the idea what's wrong with it?
 
D

Dave Thomas

require 'ftools'
def fcmp
from = 'my_log.txt'
to = 'my_log_e.txt'
if compare(from,to, verbose = false) then
puts 'Identical.'
else
puts 'Different.'
end
end

After running the function. There's no result as all. Is there anybody
has the idea what's wrong with it?


You probably need to call your function.


Dave
 
C

Cheyne Li

Dave said:
You probably need to call your function.


Dave

Hi, Dave

I tried put them in a class, and tested, but it kept throwing me the
error message. The code and error message are in the following:

class Cmprocess
# Create the object
def initialize(from,to)
@from = from
@to = to
end

def fcmp
require 'ftools'
compare(@from,@to, true)
end

r= Cmprocess.new("my_log.txt","my_log_e.txt")

if r.fcmp then
puts "Identical files."
else
puts "Different files."
end

end


C:\Documents and Settings\cheynel\My
Documents\NetBeansProjects\task1\lib\fcmp.rb:11:in `fcmp': undefined
method `compare' for #<Cmprocess:0xb40ec4 @to="my_log_e.txt",
@from="my_log.txt"> (NoMethodError)
from C:\Documents and Settings\cheynel\My
Documents\NetBeansProjects\task1\lib\fcmp.rb:16
from C:\Documents and Settings\cheynel\My
Documents\NetBeansProjects\task1\lib\fcmp.rb:2


I used netbean for ruby to ran it
 
D

Dave Thomas

I tried put them in a class, and tested, but it kept throwing me the
error message. The code and error message are in the following:


1. It's relatively unusual to create instances of a class inside the
class body, but that won't cause this problem

2. Where do you define the 'compare' method?


Dave
 
C

Cheyne Li

Dave said:
1. It's relatively unusual to create instances of a class inside the
class body, but that won't cause this problem

2. Where do you define the 'compare' method?


Dave

compare is a std mathod in ftools.rb
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top