From: Robert Klemme Date: 2010-04-25T19:40:06+09:00 Subject: Re: Defining your own typecaster On 04/25/2010 02:01 AM, Vinícius Baggio Fuentes wrote: > [Note: parts of this message were removed to make it a legal post.] > > I've seen the following declaration, which I think it is valid: > > module Kernel > def Foo(*objs) > Foo.new(objs) > end > end > > I'm not sure if there's another way one could achieve that, but works for > the purpose. That's typically how they are done. And I believe methods are also made private to disallow calling them with self: irb(main):001:0> Integer("1") => 1 irb(main):002:0> self.Integer("1") NoMethodError: private method `Integer' called for main:Object from (irb):2 from /usr/local/bin/irb19:12:in `
' irb(main):003:0> And you should probably forward the block if given. So the complete idiom looks like this: module Kernel def Foo(*objs, &b) Foo.new(objs, &b) end private :Foo end Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/