how do you extend a class externally?
module B
...
end
class A
...
end
# ???
A.include(B)
A.extend(B)
A.append_features(B)
A.class_eval { include B }
none of these work.
···
–
tom sawyer, aka transami
transami@transami.net
how do you extend a class externally?
module B
...
end
class A
...
end
# ???
A.include(B)
A.extend(B)
A.append_features(B)
A.class_eval { include B }
none of these work.
–
tom sawyer, aka transami
transami@transami.net
Tom Sawyer wrote:
how do you extend a class externally?
module B ... end class A ... end # ??? A.include(B)
A.instance_eval {include(B)}
appears to work.
But then again, there is no need to extend it externally in Ruby. You
can always reopen a class scope and do
class A; include B; end
–
([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_/ö____/ (_engineering.discipline=Computer::Technology)
Tom Sawyer wrote:
how do you extend a class externally?
module B
…
endclass A
…
end???
A.include(B)
A.extend(B)
A.append_features(B)
A.class_eval { include B }none of these work.
class A
include B
end
…if I remember correctly.
HTH
Stephan
how do you extend a class externally?
module B
…
endclass A
…
end???
A.include(B)
include is private
A.extend(B)
This works, but doesn’t do what you want as it is performed on singleton level.
A.append_features(B)
this is private too
A.class_eval { include B }
This works, AFAIK.
cpmf2196@l4 ~ $ ruby
class A
end
module B
def boo
p “BOO”
end
end
A.class_eval “include B”
A.new.boo
“BOO”
none of these work.
Is there a reason for Module (Class?, have no ri here)#include to be private?
On Fri, Jan 24, 2003 at 06:40:21PM +0900, Tom Sawyer wrote:
–
_ _
__ __ | | ___ _ __ ___ __ _ _ __
'_ \ /| __/ __| '_
_ \ / ` | ’ \
) | (| | |__ \ | | | | | (| | | | |
.__/ _,|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
#if _FP_W_TYPE_SIZE < 64
#error “Only stud muffins allowed, schmuck.”
#endif
– linux/arch/sparc64/quad.c
A.instance_eval {include(B)}
appears to work.
really
But then again, there is no need to extend it externally in Ruby. You
can always reopen a class scope and do
class A; include B; end
Doh! i knew that. what was i thinking? kind of odd that there’s no direct
method for it though.
anyhow, i implemented it and it greatly slowed down my app. oh well, although
i wanted better SOC i went back to including the modules into the original
classes.
On Friday 24 January 2003 02:48 am, Kent Dahl wrote:
–
tom sawyer, aka transami
transami@transami.net
A.extend(B)
This works, but doesn’t do what you want as it is performed on singleton
level.A.append_features(B)
this is private too
A.class_eval { include B }
funny, my code was bombing on these. no matter though as they aren’t
preferable solutions anyway.
Is there a reason for Module (Class?, have no ri here)#include to be
private?
i would like to know this too. matz?
On Friday 24 January 2003 05:19 am, Mauricio Fernández wrote:
–
tom sawyer, aka transami
transami@transami.net