From: Michael Guterl Date: 2006-08-16T03:46:35+09:00 Subject: Re: Instance and Related Class Methods ------=_Part_109144_31227245.1155667591949 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/15/06, Eero Saynatkari wrote: > > Michael Guterl wrote: > > I have a class with a lot of instance methods which are related to > > class methods from within the same class. > > > > Example: > > > > > > > > Everything works as expected. However, I am wondering if there is a > > more Rubyish way of accomplishing this so I can avoid the repetition. > > Any other suggestions are welcome. Thanks in advance. > > The simplest thing would be to eliminate these calls on > the instances completely since no instance data is needed. I'm not sure I understand. I would like to have access to both class and instance methods. Basically some of my code looks like this. day = A.new(1.days.ago, Time.now) hour = A.new(1.hour.ago, Time.now) Then I would also like to be able to use arbitrary starting and ending ranges with the class method, without the need to create an instance. total_incoming = A.total_incoming(1.year.ago, Time.now) If you do want to do this, you can automate it by creating > a #method_missing handler for the instance methods--it will > check whether a class method by the same name exists and > then forward to it (falling back on the normal #method_missing > on failure). > Michael Guterl > > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_109144_31227245.1155667591949--