# Problem with files comparing

**URL:** <https://www.ruby-forum.com/t/problem-with-files-comparing/137417>\
**Category:** Ruby\
**Created:** [May 12, 2008, 11:58pm UTC](https://www.ruby-forum.com/t/problem-with-files-comparing/137417 "2008-05-12T23:58:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheyne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cheyne](https://www.ruby-forum.com/u/cheyne)\
**Post date:** [May 12, 2008, 11:58pm UTC](https://www.ruby-forum.com/t/problem-with-files-comparing/137417/1 "2008-05-12T23:58:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cheyne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cheyne](https://www.ruby-forum.com/u/cheyne)\
**Post date:** [May 13, 2008, 12:04am UTC](https://www.ruby-forum.com/t/problem-with-files-comparing/137417/2 "2008-05-13T00:04:54Z")

</div>

On May 12, 2008, at 4:58 PM, Cheyne Li wrote:

> 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

---

<div class="post-metadata">

**Author:** ![cheyne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cheyne](https://www.ruby-forum.com/u/cheyne)\
**Post date:** [May 13, 2008, 12:29am UTC](https://www.ruby-forum.com/t/problem-with-files-comparing/137417/3 "2008-05-13T00:29:12Z")

</div>

Dave T. wrote:

> On May 12, 2008, at 4:58 PM, Cheyne Li wrote:
> 
> > 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

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

---

<div class="post-metadata">

**Author:** ![cheyne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cheyne](https://www.ruby-forum.com/u/cheyne)\
**Post date:** [May 13, 2008, 12:35am UTC](https://www.ruby-forum.com/t/problem-with-files-comparing/137417/4 "2008-05-13T00:35:21Z")

</div>

On May 12, 2008, at 5:29 PM, Cheyne Li wrote:

> 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

---

<div class="post-metadata">

**Author:** ![cheyne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cheyne](https://www.ruby-forum.com/u/cheyne)\
**Post date:** [May 13, 2008, 6:21pm UTC](https://www.ruby-forum.com/t/problem-with-files-comparing/137417/5 "2008-05-13T18:21:31Z")

</div>

Dave T. wrote:

> On May 12, 2008, at 5:29 PM, Cheyne Li wrote:
> 
> > 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

compare is a std mathod in ftools.rb

---

<div class="post-metadata">

**Author:** ![cheyne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cheyne](https://www.ruby-forum.com/u/cheyne)\
**Post date:** [May 13, 2008, 6:28pm UTC](https://www.ruby-forum.com/t/problem-with-files-comparing/137417/6 "2008-05-13T18:28:40Z")

</div>

On May 13, 2008, at 11:21 AM, Cheyne Li wrote:

> compare is a std mathod in ftools.rb

Then you’d need to say File.compare, and not just compare.

Dave

---

<div class="post-metadata">

**Author:** ![cheyne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cheyne](https://www.ruby-forum.com/u/cheyne)\
**Post date:** [May 13, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/problem-with-files-comparing/137417/7 "2008-05-13T19:53:40Z")

</div>

Dave T. wrote:

> On May 13, 2008, at 11:21 AM, Cheyne Li wrote:
> 
> > compare is a std mathod in ftools.rb
> 
> Then you’d need to say File.compare, and not just compare.
> 
> Dave

Ok. I c. Thanks man
