Coercion of variables

Yukihiro Matsumoto wrote:

How about extending the socket with your module. See Object#extend.
   
  s = ss.accept
  s.extend YourSocketExtensionModule
  ...

Yep, that's the solution I have been using. I just wondered, after seeing
the '<<' syntax, whether there was another way I had missed.

I have also seen "coerce" used in error messages: for example

irb(main):001:0> 0 < Time.now
TypeError: Time can't be coerced into Fixnum

Time does have a 'to_i' method, so is this some other sort of coercion?

Thanks,

Brian.

Hi,

···

In message “Re: Coercion of variables” on 03/02/02, Brian Candler B.Candler@pobox.com writes:

irb(main):001:0> 0 < Time.now
TypeError: Time can’t be coerced into Fixnum

Time does have a ‘to_i’ method, so is this some other sort of coercion?

Implicit coercion requires ‘coerce’ or ‘to_int’ method, not just
‘to_i’.

						matz.