From: MustModify Date: 2010-04-26T23:50:07+09:00 Subject: Re: Defining your own typecaster > module Kernel >   def Foo(*objs) >     Foo.new(objs) >   end > end This is a valid solution to the problem, but I'm wondering why you want to do type casting. Typically if you're working in Ruby and you're looking at that kind of declaration, you've come from C# or Java or something and you just aren't in the groove yet. If you give us some context, we might be able to give you a better push. I wrote a gem called Valuable ( http://valuable.mustmodify.com/ ) that implements very simple type casting for instance attributes. It's useful in situations where like gets and in Rails where your input often comes in as a string and you don't want to have to worry with the logic of casting nil.to_i on accident, etc. class BaseballPlayer has_value :hits, :klass => :integer has_value :runs, :klass => :integer has_value :team has_value :phone_number, :klass => PhoneNumber def rbi (hits / runs.to_f) if hits && runs end end >> joe = BaseballPlayer.new(:hits => '24', :runs => '12', :team => 'Dragons') >> joe.phone_number => 1234567890 >> joe.runs => 12 >> joe.rbi => 0.5 >> joe.runs = nil >> joe.rbi => nil >> joe.phone_number => "(123) 456-7890" ---------- Johnathon Wright Web Application Consultant http://blog.mustmodify.com/