On 19 Jun 2012, at 21:57, Henry Maddocks wrote:

> 2. Visibility. If you ask for the ancestors of the base class you will =
see your module in the list which will give users a clue why the class =
isn't behaving in a standard way and a pointer to where they should =
start looking.
>=20
> String.ancestors
> =3D> [String, MyStringExtensions, Comparable, Object, Kernel, =
BasicObject]=20

That's a really good idea, thanks.

>=20
> 3. Targeted extension. Using extend you can apply your monkey to =
specific objects rather than every object of that type in the system. =
Though, as @Bartosz pointed out, this may cause performance =
degradation's.
>=20
> a =3D "asdfghj"                                           # =3D> =
"asdfghj"=20
> b =3D "2345678"                                        # =3D> =
"2345678"=20
> b.extend MyStringExtensions
> a.foo                                                         # =
NoMethodError: undefined method `foo' for "asdfghj":String
> b.foo                                                        #  =3D> =
"bar"=20
>=20

I just learnt about this yesterday, and though it's not applicable for =
the situation I've got at the moment, it's good to know, and this is the =
first code example of it I've seen too.

Much appreciated.

Regards,
Iain