Module_eval via a wrapper method does not rewrite klass

Yuguie$B$G$9!#e(B

http://d.hatena.ne.jp/viver/20080107/p1 e$B$K=q$+$l$F$$$kLdBj$re(B
e$BD4$Y$F$_$^$7$?!#e(B
module_evale$B$rB>$N%a%=%C%I$G$/$k$`$H!"%a%=%C%[email protected]$,=q$-49e(B
e$B$o$C$F$$$^$;$s!#e(B

e$B$b$&>/$7>$7$$>u67$,e(B http://d.hatena.ne.jp/viver/20080109/
p1 e$B$KJs9p$5$l$F$$$^$9!#e(B

e$B8=:_$Ne(Btrunke$B$G$b:F8=$7$^$9!#e(B[ruby-dev:34093]e$B$H$OD>e(B
[email protected]$N4X78$O$J$5$=$&$G$9!#e(B
e$B?\F#$5$s$N%Q%C%A$rEv$F$F$b:F8=$7$^$9!#e(B

module_eval.rb:

class Module
def my_module_eval(&block)
module_eval(&block)
end
end
class String
Integer.my_module_eval do
def hoge; end
end
end
p Integer.instance_methods(false).map{|m|m.to_sym}.include?(:hoge)
p String.instance_methods(false).map{|m|m.to_sym}.include?(:hoge)

e$B$3$l$r<B9T$9$k$H!"<!$N$h$&$G$9!#e(B
$ ruby -v module_eval.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.2.0]
true
false
$ ruby-trunk -v module_eval.rb
ruby 1.9.0 (2008-03-29 revision 0) [i686-darwin9.2.0]
false
true

vm_insnhelper.c:1074 (vm_define_method)e$B$K$Fe(Bklass = cref->nd_class
e$B$,!“K\Mhe(B
rb_cIntegere$B$G$”$k$Y$-$H$3$m!"e(Brb_cStringe$B$K$J$C$F$$$^$9!#e(B

e$B%U%l!<%`[email protected]$J}$rD4$Y$h$&$H$7$?$N$G$9$,!";d$NCN<1$G$O$^[email protected]}e(B
e$B2r$G$-$F$$$^$;$s!#e(B
e$B$b$&>/$7D4$Y$F$
$k$D$b$j$G$$$^$9$,!"<1<T$K65$([email protected]$1$k$He(B
e$B4r$7$$$G$9!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs