From: "Damián M. González" Date: 2012-09-27T21:30:35+09:00 Subject: Re: Subclassing Date > Why are you subclassing Date in the first place? Well, the class Dia(It's day in spanish) represent a day. Each instance of this class have like 10 inst. variables. I wanted to subclass Date because I want to be available +() or -() or cweek() to a Dia instance, in the way that it behave like a Date object does. >You can use composition instead of subclassing, as in > >require 'date' > > class Dia > def initialize(ano, mes, dia, obj_mes) > @mes=obj_mes > @d = Date.new(ano,mes,dia) > end > def print() > printf "date = %04d-%02d-%02d : obj_mes = %-s\n ", > @d.year, @d.month, @d.day, @mes > end > end > >a = Dia.new(2012, 6, 21,"foo") >a.print() > >__END__ > >Output: >[2012/09/27] [11:17:47.31] [C:\_MyPrg\Ruby\Exper\Forum] >ruby subdate.rb >date = 2012-06-21 : obj_mes = foo > >HTH gfb Yes, I'll have to go for something like that, thanks. -- Posted via http://www.ruby-forum.com/.