Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Overloading Array Subtraction operator

Reply
Thread Tools

Overloading Array Subtraction operator

 
 
Robert Klemme
Guest
Posts: n/a
 
      06-11-2007
On 11.06.2007 03:25, Nicko wrote:
> On Jun 10, 8:46 pm, Robert Klemme <(E-Mail Removed)> wrote:
>> It is usually not such a good idea to inherit base classes like Array
>> and Hash. Here are two more healthy approaches.

>
> The code is meant to be getting two lists of files, one on a usb stick
> and one on a network share, putting them in hashes (for filename, size
> and md5 hash) and now i want a list of the files that are in one list
> but not on the other.


Why then don't you just substract key arrays (assuming that your keys
are file names)? Or is size and MD5 important for your comparison? In
that case I'd probably do this:

FileInfo = Struct.new :file_name, :size, :md5

If you put instances of this class in an Array or Set your substraction
logic will work.

> If the hashes are the same, they won't be the same instance because
> they were generated seperately.
>
> Why is inheriting from Array not a healthy approach?


See my other reply.

Kind regards

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
overloading operator->*() and operator->() gob00st@googlemail.com C++ 11 02-20-2009 08:52 PM
user defined conversion operator or operator overloading? hurcan solter C++ 3 08-29-2007 07:39 PM
Why is overloading operator. (member operator) forbidden? dascandy@gmail.com C++ 11 05-16-2007 07:54 PM
Operator overloading on "default" operator John Smith C++ 2 10-06-2004 10:22 AM
Overloaded subtraction operator - memory problem August1 C++ 4 09-21-2004 12:57 AM



Advertisments