PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Problem with files comparing
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Problem with files comparing

Réponse
 
LinkBack Outils de la discussion
Vieux 12/05/2008, 22h58   #1
Cheyne Li
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Problem with files comparing

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

  Réponse avec citation
Vieux 12/05/2008, 23h04   #2
Dave Thomas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with files comparing


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

  Réponse avec citation
Vieux 12/05/2008, 23h29   #3
Cheyne Li
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with files comparing

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

  Réponse avec citation
Vieux 12/05/2008, 23h34   #4
Dave Thomas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with files comparing


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

  Réponse avec citation
Vieux 13/05/2008, 17h21   #5
Cheyne Li
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with files comparing

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

  Réponse avec citation
Vieux 13/05/2008, 17h27   #6
Dave Thomas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with files comparing


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

  Réponse avec citation
Vieux 13/05/2008, 18h53   #7
Cheyne Li
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problem with files comparing

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h02.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13125 seconds with 15 queries