-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
| Eustaquio,
Hey Daniel.
| Later, when you say this,
| foo.moomin
| Ruby sees that `foo' is divisible by four and so must be a pointer to
| an object, and a regular method call is made. But when you say this,
A regular method is called on the object at a memory location allocated
for the object value OR for value and a representation of the object
class, with methods and so on?
What is pointed by, let's say, a variable who stores a reference to a
String like "this is a long string where I can write a lot of things" is
just the string value or a complete package with it's value and methods?
What will be released by the garbage collector is the answer of the
question above (memory allocated for values OR for values and methods),
when is not needed anymore, right?
For example on
s1, s2, s3, s4 =3D "this","is","a","test"
s1, s2, s3, s4 shares the String methods and their references points to
memory locations only with "this" "is" "a" "test", querying the String
methods on a String representation
OR
the reference to "this" & object methods, "is" & object methods, "a" &
object methods and "test" & object methods?
So it's like
~ +-------- gc works here ------------+
~ | |
~ +--------+---------+ +---------+ +---------+--------+
~ | memory allocated | | String | | memory allocated |
~ +------------------+ +---------+ +------------------+
~ | value | | methods | | value |
~ +------------------+ +---------+ +------------------+
s1 =3D | "this" +--+ upcase +--+ "is" | =3D s2
~ +------------------+ +---------+ +------------------+
or like
~ +-------- gc works here -------+
~ | |
~ +---------+---------+ +--------+---------+
~ | memory allocated | | memory allocated |
~ +---------+---------+ +--------+---------+
~ | value | methods | | value | methods |
~ +---------+---------+ +--------+---------+
s1 =3D | "this" | upcase | s2 =3D | "is" | upcase |
~ +---------+---------+ +--------+---------+
I think it should be first one, specially when we change the String
class at runtime and it changes all the String references, but I'm
asking just to be sure.
| bar.snufkin
| it sees that `bar' contains 85, which is an odd integer --- not
| divisible by four. The oddness means that `bar' is an immediate
| Fixnum, so Ruby converts the value to its real meaning by subtracting
| one and halving it, giving 42. Then the method `snufkin' is looked up
| in the Fixnum class and invoked with `self' bound to 42.
That give us the value of the Fixnum, where we can find it's real value,
as you explained, and on this case the method (snufkin) is looked up on
a generic (or "internal") Fixnum class, like I supposed String above,
not on the reference (the reference is the own object) as above right?
Kind of
n1, n2 =3D 1, 2
~ +-------+ +---------+ +-------+
~ | value | | methods | | value |
~ +-------+ +---------+ +-------+
n1 =3D | 1 +---| succ +---+ 2 | =3D n2
~ +-------+ +---------+ +-------+
So we can make math right with it's value, as Robert said, not needing
to make an overhead with methods and so on, right?
Robert answered me about this but his email is on my mailbox on my job. :=
-(
| Okay, I realize that this explanation turned out pretty confusing.
| For more information, you might search for ``ruby immediate values.''
No, I really appreciated it. Thank you very much. Sorry for bore you
guys with this kind of thing but I'm really curious.
I searched for that on the web, but I really needed some more "deeper"
info, because there's a lot of places with just replicate the pickaxe
contents.
Best regards,
- ----------------------------
Eust=E1quio "TaQ" Rangel
http://beam.to/taq
Usu=E1rio GNU/Linux no. 224050
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCxfEtb6UiZnhJiLsRApkXAJ0a1xSF7bmj19Athamio4 BO0W69CgCeLsHN
BHaE1nxEz5IpquPKw2cRiVA=3D
=3Do8UT
-----END PGP SIGNATURE-----