summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora_matsuda <a_matsuda@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-15 10:43:17 +0000
committera_matsuda <a_matsuda@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-15 10:43:17 +0000
commit88de87c2952b08d7f264c7788069a9b6c2fa9309 (patch)
tree17ead6b2af6068c03937b9c0d023f0064588be98
parente64e3c4c21361565fa03c49292e6918e0eb7f693 (diff)
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
-rw-r--r--lib/irb/magic-file.rb2
-rw-r--r--lib/irb/src_encoding.rb6
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/irb/magic-file.rb b/lib/irb/magic-file.rb
index 2dee684..34e06d6 100644
--- a/lib/irb/magic-file.rb
+++ b/lib/irb/magic-file.rb
@@ -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)
diff --git a/lib/irb/src_encoding.rb b/lib/irb/src_encoding.rb
index 32f997f..99aea2b 100644
--- a/lib/irb/src_encoding.rb
+++ b/lib/irb/src_encoding.rb
@@ -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