ruby-changes:46975
From: a_matsuda <ko1@a...>
Date: Thu, 15 Jun 2017 19:43:22 +0900 (JST)
Subject: [ruby-changes:46975] a_matsuda:r59090 (trunk): Don't pollute toplevel by an IRB internal method
a_matsuda 2017-06-15 19:43:17 +0900 (Thu, 15 Jun 2017) New Revision: 59090 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59090 Log: Don't pollute toplevel by an IRB internal method There actually are some libraries that requires 'irb' such as byebug, and when 'irb' is required, it requires irb/src_encoding.rb, then it defines the toplevel default_src_encoding method that is visible from anywhere in the end users' apps. Here's a quick oneliner that shows what's happening. % ruby -rpry-byebug -e 'p private_methods(false)' [:include, :using, :define_method, :public, :private, :DelegateClass, :default_src_encoding] Modified files: trunk/lib/irb/magic-file.rb trunk/lib/irb/src_encoding.rb Index: lib/irb/magic-file.rb =================================================================== --- lib/irb/magic-file.rb (revision 59089) +++ lib/irb/magic-file.rb (revision 59090) @@ -10,7 +10,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/magic-file.rb#L10 line = io.gets if line[0,2] == "#!" encoding = detect_encoding(line) internal_encoding = encoding - encoding ||= default_src_encoding + encoding ||= IRB.default_src_encoding io.rewind io.set_encoding(encoding, internal_encoding) Index: lib/irb/src_encoding.rb =================================================================== --- lib/irb/src_encoding.rb (revision 59089) +++ lib/irb/src_encoding.rb (revision 59090) @@ -1,5 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/irb/src_encoding.rb#L1 # frozen_string_literal: false # DO NOT WRITE ANY MAGIC COMMENT HERE. -def default_src_encoding - return __ENCODING__ +module IRB + def self.default_src_encoding + return __ENCODING__ + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/