[fxruby-users] Inheritance

Uwe Hartl uwe.hartl at gmx.net
Thu Feb 9 16:01:31 EST 2006


Hi Joel,
Thank you very much. It works like a charm!
I have chosen the "factory" approach, because there I can inherit my 
DataFixNum from other classes:

class DataFixNum
	def print
		puts "I am a DataFixNum!   " + self.to_s
	end
end
class DataTime
	def print
		puts "I am a DataTime!   " + self.to_s
	end
end
class Data
	def self.new(value)
		case value
			when Fixnum; DataFixNum.new
			when Time; DataTime.new
		end
	end
end
Data.new(23).print
Data.new(Time.now).print


Is there a particular reason why I should not use "new" here instead of 
"self.new_from_value(d)" as you suggested?

Thanks again

Uwe


On Thursday 09 February 2006 20:58, Joel VanderWerf wrote:
>      class Data
>        def self.new_from_value(d)
>          case value
>          when Fixnum; DataFixNum.new
>          when Date; ....
>        end
>      end

-- 
***********************************************************************
Uwe Hartl                                e-mail: Uwe.Hartl at gmx.net
91522 Ansbach                            Telephone: (0981) 9724526
Am Mühlfeld 8                            Notfall-Mobil: (0160)90418680
Germany
***********************************************************************




More information about the fxruby-users mailing list