On Sat, Mar 9, 2013 at 9:08 PM, Hans Mackowiak <[email protected]> wrote:
> because ruby is very strong typed, it does not have casting per se,

I disagree: there is no casting - but for other reasons: Ruby does not
have casting because it is _dynamically_ typed. You cannot get into a
situation where you need to cast an expression to another type because
there is no static type information at all.

Unfortunately in C++ land the term "casting" is also often used for
"conversion" because that is done via the cast operator.  I prefer to
use "cast" only for changes which do not affect the memory
representation, i.e. changing the type of reference in Java or
reinterpreting a bit pattern in memory as a different type.
http://en.wikipedia.org/wiki/Type_conversion

> so without bad Hacks an object cant change its own type/class.

Right.

> so to_i and others are always conversion.
> but ruby has different kinds ...
> to_int is implicit conversion, but only exist for classes which are
> already a number.
> to_i is explicit conversion. it exist for other classes like String too
>
>
> when the core defined methods wants an Integer for sample, ruby
> automatic tries to call to_int, but not to_i for non-Integer

It is more complex when you consider mathematical operators, because
then conversion usually depends on two values instead of one. See
http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.html

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- 
[email protected] | 
https://groups.google.com/d/forum/ruby-talk-google?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to