2012/11/7 Regina George <lists / ruby-forum.com>:
> Our challenge was to find out if type confusion was possible in other
> languages, and my group got assigned Ruby. Can anyone offer some insight
> or point to some resources?

Every variable in your Ruby code in (internally) a C type called
"VALUE", which is just a typedefed unsigned int pointer. This pointer
points to a larger structure (in C, RBasic and other structs based on
it, like RString), from which you can read the value's class and other
properties. (Technically, this works differently for Ruby Fixnums and
Symbols, whose values are magically encoded in the pointer value
itself.)

So it's not possible to have force this kind of behavior you describe
in Ruby. However, as 7stud pointed out, instance variables (which are
like private fields in Java) can be accessed and modified anyway with
a little magic, and private or protected methods can be with some
tricks called from the outside environment. This is by design, as far
as I know.

-- Matma Rex