# Methods depend on pairs of objects - best parctise pls?

**URL:** <https://www.ruby-forum.com/t/methods-depend-on-pairs-of-objects-best-parctise-pls/172632>\
**Category:** Ruby\
**Created:** [July 24, 2009, 9:19am UTC](https://www.ruby-forum.com/t/methods-depend-on-pairs-of-objects-best-parctise-pls/172632 "2009-07-24T09:19:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![orenshani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e47c2d/32.png) [@orenshani](https://www.ruby-forum.com/u/orenshani)\
**Post date:** [July 24, 2009, 9:19am UTC](https://www.ruby-forum.com/t/methods-depend-on-pairs-of-objects-best-parctise-pls/172632/1 "2009-07-24T09:19:01Z")

</div>

Hi All,

First of all I think you should know that I am quite new to Ruby. I have  
may years of experience with other programming languages tough, and I  
must say that Ruby is really great!

And now to my question - I am working on something that makes use of  
proximity functions, which are functions that take two objects (“base”  
and “reference”) and return a real number in the range of [0…1], based  
on how “the same” the objects are (1 means identical, 0 means completley  
different and a fractions means a certain degree of proximity). The  
objects do not have to be of the same type. For example, a number can be  
compared to a range, a string can be compared to a regular expression,  
etc, but of course, not all combinations are possible.

Now the point is that the process for calculating the proximity very  
much depends on the types of objects compared, so it is actually a  
method of the objects-pair, so the most obvious thing I can do is define  
a class for each valid pair combination, but that does not seem to me as  
very elegant. Another thing I can do is to define the proximity function  
as a method of each object and somehow re-define the needed sub-methods  
per each class of valid reference-object, but that still looks a little  
messy, I think.

So does anyone have any other ideas for doing this kind of object-pairs  
dependent coding, is ther some kind of best-practice for this situation?

Your thoughts and ideas are much appreciated!

Oren
