なかだです。

クラス定義の中でstrscanをrequireすると、トップレベルとは別の
StringScannerができてしまいます。

$ ruby -vwe 'class Foo; require "strscan"; end; p StringScanner.constants, Foo::StringScanner.constants'
ruby 1.9.0 (2004-02-17) [i686-linux]
["Id", "Version"]
["Error"]


* ext/strscan/strscan.c (Init_strscan): should not be affected by
  outer bindings.

Index: ext/strscan/strscan.c =================================================================== RCS file: /cvs/ruby/src/ruby/ext/strscan/strscan.c,v retrieving revision 1.8 diff -u -2 -p -d -r1.8 strscan.c --- ext/strscan/strscan.c 17 Feb 2004 09:02:41 -0000 1.8 +++ ext/strscan/strscan.c 18 Feb 2004 07:12:03 -0000 @@ -800,8 +800,12 @@ void Init_strscan() { - volatile VALUE tmp; + ID id_scanerr = rb_intern("ScanError"); + VALUE tmp; StringScanner = rb_define_class("StringScanner", rb_cObject); - ScanError = rb_eval_string("class StringScanner; class Error < StandardError; end; end; ScanError = StringScanner::Error unless defined?(ScanError); StringScanner::Error"); + ScanError = rb_define_class_under(StringScanner, "Error", rb_eStandardError); + if (!rb_const_defined(rb_cObject, id_scanerr)) { + rb_const_set(rb_cObject, id_scanerr, ScanError); + } tmp = rb_str_new2(STRSCAN_VERSION); rb_obj_freeze(tmp);
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦