Do you have a preferred programming pattern for adding functionality to
an ActiveRecord? As an example, say I have some gnarly trig functions
for distance and bearing between pairs of latitude and longitude:
=== file: latlng.rb
def haversine_distance(lat1, lng1, lat2, lng2)
def bearing(lat1, lng1, lat2, lng2)
… and I want to mix in haversine_distance(other_ar) and
bearing(other_ar) methods into an ActiveRecord. The shim functions
would look like this:
haversine_distance(self.lat, self.lng, other_ar.lat, other_ar.lng)
bearing(self.lat, self.lng, other_ar.lat, other_ar.lng)
BUT: What are your preferred methods for packing this up in to modules?
What are the preferred names for modules? Where do you put the files?
Do you include the computational methods in the same file as the shim
Extending AR functionality is relatively common, but I haven’t yet seen
a dominant pattern for doing so. I don’t expect really coherent answers
from such an open ended question, but I’m curious what techniques people
have seen and like.