From: Malte Milatz Date: 2004-06-27T23:33:02+09:00 Subject: Re: Newbie: How to model this? Ralph Aichinger wrote: > class Location > def initialize(lon,lat,hgt) > @lon = lon > @lat = lat > @hgt = hgt > end > end > > I want methods like myPoint.dmsdegrees giving just the degrees > part of myPoint in degree, minute, second format. These should be > "virtual attributes" if I understand Thomas/Hunt right. > > How can I define this in the most elegant fashion? I cannot let Location > inherit this from a base class "Angle" with all these conversion > methods, can I, because a Location is not a Angle, at least not just > a Angle. I would do it like this (or similar): class Location attr_accessor :lon, :lat, :hgt def initialize(lon,lat,hgt) @lon = DegreeValue.new(lon) @lat = DegreeValue.new(lat) @hgt = FootValue.new(hgt) end end class DegreeValue < Float def dms # Some calculation [ degrees, minutes, seconds ] end end Alternatively you could add Numeric#dms. -- My email address is malte at gmx-topmail.de