M
Michael Guterl
I have a class with a lot of instance methods which are related to
class methods from within the same class.
Example:
class A
def initialize(start_date, end_date)
@start_date, @end_date = start_date, end_date
end
def total_hours
A.total_hours(@start_date, @end_date)
end
def self.total_hours(start_date, end_date)
self.sumhours, :conditions => between(start_date, end_date))
end
def total_incoming
A.total_incoming(@start_date, @end_date)
end
def self.total_incoming(start_date, end_date)
self.sumincoming, :conditions => between(start_date, end_date))
end
def total_outgoing
A.total_outgoing(@start_date, @end_date)
end
def self.total_outgoing(start_date, end_date)
self.sumoutgoing, :conditions => between(start_date, end_date))
end
end
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.
Michael Guterl
class methods from within the same class.
Example:
class A
def initialize(start_date, end_date)
@start_date, @end_date = start_date, end_date
end
def total_hours
A.total_hours(@start_date, @end_date)
end
def self.total_hours(start_date, end_date)
self.sumhours, :conditions => between(start_date, end_date))
end
def total_incoming
A.total_incoming(@start_date, @end_date)
end
def self.total_incoming(start_date, end_date)
self.sumincoming, :conditions => between(start_date, end_date))
end
def total_outgoing
A.total_outgoing(@start_date, @end_date)
end
def self.total_outgoing(start_date, end_date)
self.sumoutgoing, :conditions => between(start_date, end_date))
end
end
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.
Michael Guterl