--8323328-1989049411-1122484267=:4734
Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1989049411-1122484267=:4734"
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
--8323328-1989049411-1122484267=:4734
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE
Hmm, for some reason this part of your message was left out
of my reply buffer, so I forgot to reply to it!
Ara.T.Howard said:
That's not instantiating a module. It's cute, but it's
not instantiating a module.
Of course it's not instantiating a module, but it's
pretty much _as good as_ instantiating a module. It lets
you use modules instead of classes, which demonstrates
that the distinction is superficial.
does it?
[Complicated way of saying module.new.class !=3D module.]
As I trust you are already aware, that's easily fixed:
Just redefine the =E2=80=98class=E2=80=99 method to return the module.
yes - just pointing out there's more to being a class than having a new
method...
Yes, you can:
module N
include M
end
the problem is a bit deeper than that and stem from the fact that including=
a
module does not inject the included modules singleton methods into the
'includee'. for example (note this has the fix suggested above):
harp:~ > cat a.rb
class Module
def new(*a, &b)
(@__klass__ ||=3D (m =3D self and Class::new{ include(@@m =3D m); de=
f class;@@m;end }))::new(*a, &b)
end
end
module M
class << self
def class_method
42
end
end
def instance_method
42
end
end
module N
include M
end
begin
m =3D M::new
p m.class
p m.instance_method
p m.class.class_method
rescue =3D> e
puts "#{ e.message } (#{ e.class }"
end
begin
n =3D N::new
p n.class
p n.instance_method
p n.class.class_method
rescue =3D> e
puts "#{ e.message } (#{ e.class }"
end
harp:~ > ruby a.rb
M
42
42
N
42
undefined method `class_method' for N:Module (NoMethodError
i'm not saying it's not possible - just that it's a bit more work than you'=
re
suggesting. doing things consistently at an object, class, module, and
singleton_class level gets very confusing very quicky - just check out the =
code
for my traits lib to see just how. ;-)
i personally often get around this detail by
module M
module ClassMethods
end
module InstanceMethods
end
include InstanceMethods
self.extend ClassMethods
def self::included other
class << other
include InstanceMethods
end
other.extend ClassMethods
end
end
or something similar - in otherwords factor out class methods so that can b=
e
added individually to other classes/modules when they are included there.
thus begins the trickiness...
(ps. for some reason the charset from your message is very odd - it may be =
on
my end but thought you might like to know. it looks like some sort of esca=
pe
chars around '@' signs - coloring?)
cheers.
-a
--=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| My religion is very simple. My religion is kindness.
| --Tenzin Gyatso
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
--8323328-1989049411-1122484267=:4734--
--8323328-1989049411-1122484267=:4734--