[Backport #1915] const_defined?の1.9との挙動の違いについて

Backport #1915: const_defined?e$B$Ne(B1.9e$B$H$N5sF0$N0c$$$K$D$$$Fe(B
http://redmine.ruby-lang.org/issues/show/1915

e$B5/I<<Te(B: Akira M.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$B%+%F%4%je(B: core

e$B0J2<$N>l9g$Ke(B
% cat const_defined.rb
class Alpha
class Beta; end
end

class Gamma < Alpha; end

puts Gamma::const_get(Alpha)

puts Gamma::const_defined?(Alpha)

1.8e$B$He(B1.9e$B$G$O$=$l$>$l$3$&$J$j$^$9!#e(B
% ruby18 -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
% ruby18 const_defined.rb
Alpha
false
% ruby19 -v
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9.7.0]
% ruby19 const_defined.rb
Alpha
true

1.9e$B$+$i;EMM$,JQ99$5$l$?$H$$$&$3$H$J$N$+$J!"$H;W$&$N$G$9$,!"$3$l$Oe(B1.8.xe$B$K%P%C%/%]!<%H$5$l$kM=Dj$O$"$k$N$G$7$g$&$+!)e(B

e$B%A%1%C%He(B #1915 e$B$,99?7$5$l$^$7$?!#e(B (by Akira M.)

e$B$3$N7o$K4X$7$F!"@hF|$Ne(BAsakusa.rbe$B$G$$$/[email protected]$7$?$3$H$,$"$k$N$GDI5-$7$^$9!#e(B

% cat const.rb
class Alpha
class Beta; end
end

class Gamma < Alpha
puts defined?(Beta)
end

puts Gamma::const_get(Beta)

puts Gamma::const_defined?(Beta)
puts Gamma::Beta

% ruby18 const.rb
constant
Alpha::Beta
false
Alpha::Beta
% ruby19 const.rb
constant
Alpha::Beta
true
Alpha::Beta

[email protected]$7!"e(BRuby 1.9e$B$G$O!"e(B
puts Gamma::const_defined?(Beta)
e$B$N$H$3$m$re(B
puts Gamma::const_defined?(Beta, false)
e$B$H=q$1$P!"e(B1.8e$B$HF1MM$Ke(Bfalsee$B$K$J$j$^$9!#e(B

e$B$D$^$j!LdBj$Oe([email protected]$$C$F!"e(B

  1. Ruby 1.9e$B$Ne(B const_defined?
    e$B$O0z?t$re(B2e$B$D<h$l$k$h$&$K3HD%$5$l$F$$$k$,!"[email protected]$K4X$7$F$Oe(B1.8e$B$K%P%C%/%]!<%H$5$l$F$$$J$$!#e(B

1.8e$B$N5sF0e(B(defined?e$B$de(Bconst_gete$B$G8+$($F$k$N$Ke(Bconst_defined?e$B$G$O8+$($J$$e(B)e$B$,[email protected]$+L7=b$7$F$$$k$h$&$K8+$($k!#e(B
e$B$H$$$&$3$H$+$H;W$o$l$^$9!#e(B

http://redmine.ruby-lang.org/issues/show/1915

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