1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
a_matsuda 2017-06-15 10:43:17 +00:00
parent e64e3c4c21
commit 88de87c295
2 changed files with 5 additions and 3 deletions

View file

@ -10,7 +10,7 @@ module IRB
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)

View file

@ -1,5 +1,7 @@
# 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