Project

General

Profile

Actions

Backport #1915

closed

const_defined?の1.9との挙動の違いについて

Added by matsuda (Akira Matsuda) over 14 years ago. Updated over 6 years ago.

Status:
Closed
[ruby-dev:39051]

Description

=begin
以下の場合に
% 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.8と1.9ではそれぞれこうなります。
% 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.9から仕様が変更されたということなのかな、と思うのですが、これは1.8.xにバックポートされる予定はあるのでしょうか?
=end

Actions #1

Updated by matsuda (Akira Matsuda) over 14 years ago

=begin
この件に関して、先日のAsakusa.rbでいくつか判明したことがあるので追記します。

% 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

ただし、Ruby 1.9では、
puts Gamma::const_defined?('Beta')
のところを
puts Gamma::const_defined?('Beta', false)
と書けば、1.8と同様にfalseになります。

つまり、問題は2点あって、

  1. Ruby 1.9の const_defined? は引数を2つ取れるように拡張されているが、この点に関しては1.8にバックポートされていない。
  2. 1.8の挙動(defined?やconst_getで見えてるのにconst_defined?では見えない)がなんだか矛盾しているように見える。
    ということかと思われます。
    =end
Actions #2

Updated by shyouhei (Shyouhei Urabe) over 14 years ago

  • Status changed from Open to Assigned
  • Assignee set to knu (Akinori MUSHA)

=begin

=end

Updated by Gibheer (Stefan Radomski) almost 13 years ago

Hello,

i have found that behavior in rubinius too. I fixed it, so that it worked like ruby 1.9, but broke the compatibility with 1.8.
Will this be fixed in the next version of 1.8?

Updated by knu (Akinori MUSHA) over 6 years ago

  • Project changed from Ruby 1.8 to Backport187
  • Description updated (diff)
  • Status changed from Assigned to Closed

Closing this, Ruby 1.8.7 had gone EOL over three years ago.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0