[前][次][番号順一覧][スレッド一覧]

ruby-changes:55542

From: Takashi <ko1@a...>
Date: Fri, 26 Apr 2019 18:32:01 +0900 (JST)
Subject: [ruby-changes:55542] Takashi Kokubun:52cfb17086 (trunk): make sync-default-gems GEM=irb

https://git.ruby-lang.org/ruby.git/commit/?id=52cfb17086

From 52cfb17086998b9434c9c786bfcf827197216c9a Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Fri, 26 Apr 2019 18:28:54 +0900
Subject: make sync-default-gems GEM=irb

from https://github.com/ruby/irb/commit/e6739d8c66dc78562930adb0b96935c9b38acf74

diff --git a/lib/irb.rb b/lib/irb.rb
index ba12bdb..a7e7944 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -750,8 +750,8 @@ class Binding https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L750
   #
   #     Potato.new
   #
-  # Running <code>ruby potato.rb</code> will open an IRB session where
-  # +binding.irb+ is called, and you will see the following:
+  # Running +ruby potato.rb+ will open an IRB session where +binding.irb+ is
+  # called, and you will see the following:
   #
   #     $ ruby potato.rb
   #
@@ -781,7 +781,7 @@ class Binding https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L781
   #     irb(#<Potato:0x00007feea1916670>):004:0> @cooked = true
   #     => true
   #
-  # You can exit the IRB session with the +exit+ command. Note that exiting will
+  # You can exit the IRB session with the `exit` command. Note that exiting will
   # resume execution where +binding.irb+ had paused it, as you can see from the
   # output printed to standard output in this example:
   #
diff --git a/lib/irb/cmd/fork.rb b/lib/irb/cmd/fork.rb
index 31d53dc..ae4d51b 100644
--- a/lib/irb/cmd/fork.rb
+++ b/lib/irb/cmd/fork.rb
@@ -21,7 +21,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/fork.rb#L21
           class << self
             alias_method :exit, ExtendCommand.irb_original_method_name('exit')
           end
-          if block_given?
+          if iterator?
             begin
               yield
             ensure
diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index 9606c7b..2e7a3e8 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -17,24 +17,28 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L17
       on_const: ['ENV'],
     }
 
-    TOKEN_SEQ_EXPRS = {
-      on_CHAR:            [[BLUE, BOLD],            [Ripper::EXPR_END]],
-      on_const:           [[BLUE, BOLD, UNDERLINE], [Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]],
-      on_embexpr_beg:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END]],
-      on_embexpr_end:     [[RED],                   [Ripper::EXPR_END, Ripper::EXPR_ENDFN]],
-      on_ident:           [[BLUE, BOLD],            [Ripper::EXPR_ENDFN]],
-      on_int:             [[BLUE, BOLD],            [Ripper::EXPR_END]],
-      on_float:           [[MAGENTA, BOLD],         [Ripper::EXPR_END]],
-      on_kw:              [[GREEN],                 [Ripper::EXPR_ARG, Ripper::EXPR_CLASS, Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_FNAME]],
-      on_label:           [[MAGENTA],               [Ripper::EXPR_LABELED]],
-      on_qwords_beg:      [[RED],                   [Ripper::EXPR_BEG]],
-      on_regexp_beg:      [[RED, BOLD],             [Ripper::EXPR_BEG]],
-      on_regexp_end:      [[RED, BOLD],             [Ripper::EXPR_BEG]],
-      on_symbeg:          [[BLUE, BOLD],            [Ripper::EXPR_FNAME]],
-      on_tstring_beg:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]],
-      on_tstring_content: [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]],
-      on_tstring_end:     [[RED],                   [Ripper::EXPR_END]],
-    }
+    begin
+      TOKEN_SEQ_EXPRS = {
+        on_CHAR:            [[BLUE, BOLD],            [Ripper::EXPR_END]],
+        on_const:           [[BLUE, BOLD, UNDERLINE], [Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]],
+        on_embexpr_beg:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END]],
+        on_embexpr_end:     [[RED],                   [Ripper::EXPR_END, Ripper::EXPR_ENDFN]],
+        on_ident:           [[BLUE, BOLD],            [Ripper::EXPR_ENDFN]],
+        on_int:             [[BLUE, BOLD],            [Ripper::EXPR_END]],
+        on_float:           [[MAGENTA, BOLD],         [Ripper::EXPR_END]],
+        on_kw:              [[GREEN],                 [Ripper::EXPR_ARG, Ripper::EXPR_CLASS, Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_FNAME]],
+        on_label:           [[MAGENTA],               [Ripper::EXPR_LABELED]],
+        on_qwords_beg:      [[RED],                   [Ripper::EXPR_BEG]],
+        on_regexp_beg:      [[RED, BOLD],             [Ripper::EXPR_BEG]],
+        on_regexp_end:      [[RED, BOLD],             [Ripper::EXPR_BEG]],
+        on_symbeg:          [[BLUE, BOLD],            [Ripper::EXPR_FNAME]],
+        on_tstring_beg:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]],
+        on_tstring_content: [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]],
+        on_tstring_end:     [[RED],                   [Ripper::EXPR_END]],
+      }
+    rescue NameError
+      TOKEN_SEQ_EXPRS = {}
+    end
 
     class << self
       def colorable?
@@ -85,7 +89,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L89
           [BLUE, BOLD]
         elsif TOKEN_KEYWORDS.fetch(token, []).include?(str)
           [CYAN, BOLD]
-        elsif (seq, exprs = TOKEN_SEQ_EXPRS[token]; exprs&.any? { |e| (expr & e) != Ripper::EXPR_NONE })
+        elsif (seq, exprs = TOKEN_SEQ_EXPRS[token]; exprs&.any? { |e| (expr & e) != 0 })
           seq
         else
           nil
diff --git a/lib/irb/irb.gemspec b/lib/irb/irb.gemspec
index 57a44fe..d16d6b0 100644
--- a/lib/irb/irb.gemspec
+++ b/lib/irb/irb.gemspec
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec| https://github.com/ruby/ruby/blob/trunk/lib/irb/irb.gemspec#L16
   spec.homepage      = "https://github.com/ruby/irb"
   spec.license       = "BSD-2-Clause"
 
-  spec.files         = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "exe/irb", "irb.gemspec", "lib/irb.rb", "lib/irb/cmd/chws.rb", "lib/irb/cmd/fork.rb", "lib/irb/cmd/help.rb", "lib/irb/cmd/load.rb", "lib/irb/cmd/nop.rb", "lib/irb/cmd/pushws.rb", "lib/irb/cmd/subirb.rb", "lib/irb/completion.rb", "lib/irb/context.rb", "lib/irb/ext/change-ws.rb", "lib/irb/ext/history.rb", "lib/irb/ext/loader.rb", "lib/irb/ext/multi-irb.rb", "lib/irb/ext/save-history.rb", "lib/irb/ext/tracer.rb", "lib/irb/ext/use-loader.rb", "lib/irb/ext/workspaces.rb", "lib/irb/extend-command.rb", "lib/irb/frame.rb", "lib/irb/help.rb", "lib/irb/init.rb", "lib/irb/input-method.rb", "lib/irb/inspector.rb", "lib/irb/lc/.document", "lib/irb/lc/error.rb", "lib/irb/lc/help-message", "lib/irb/lc/ja/encoding_aliases.rb", "lib/irb/lc/ja/error.rb", "lib/irb/lc/ja/help-message", "lib/irb/locale.rb", "lib/irb/magic-file.rb", "lib/irb/notifier.rb", "lib/irb/output-met
 hod.rb", "lib/irb/ruby-lex.rb", "lib/irb/ruby-token.rb", "lib/irb/slex.rb", "lib/irb/src_encoding.rb", "lib/irb/version.rb", "lib/irb/workspace.rb", "lib/irb/ws-for-case-2.rb", "lib/irb/xmp.rb"]
+  spec.files         = ["LICENSE.txt", "README.md", "exe/irb", "irb.gemspec", "lib/irb.rb", "lib/irb/cmd/chws.rb", "lib/irb/cmd/fork.rb", "lib/irb/cmd/help.rb", "lib/irb/cmd/load.rb", "lib/irb/cmd/nop.rb", "lib/irb/cmd/pushws.rb", "lib/irb/cmd/subirb.rb", "lib/irb/completion.rb", "lib/irb/context.rb", "lib/irb/ext/change-ws.rb", "lib/irb/ext/history.rb", "lib/irb/ext/loader.rb", "lib/irb/ext/multi-irb.rb", "lib/irb/ext/save-history.rb", "lib/irb/ext/tracer.rb", "lib/irb/ext/use-loader.rb", "lib/irb/ext/workspaces.rb", "lib/irb/extend-command.rb", "lib/irb/frame.rb", "lib/irb/help.rb", "lib/irb/init.rb", "lib/irb/input-method.rb", "lib/irb/inspector.rb", "lib/irb/lc/.document", "lib/irb/lc/error.rb", "lib/irb/lc/help-message", "lib/irb/lc/ja/encoding_aliases.rb", "lib/irb/lc/ja/error.rb", "lib/irb/lc/ja/help-message", "lib/irb/locale.rb", "lib/irb/magic-file.rb", "lib/irb/notifier.rb", "lib/irb/output-method.rb", "lib/irb/ruby-lex.rb", "lib/irb/ruby-token.rb", "lib/irb/slex.rb", "lib
 /irb/src_encoding.rb", "lib/irb/version.rb", "lib/irb/workspace.rb", "lib/irb/ws-for-case-2.rb", "lib/irb/xmp.rb"]
   spec.bindir        = "exe"
   spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
   spec.require_paths = ["lib"]
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb
index ff8f5da..bee59b9 100644
--- a/lib/irb/workspace.rb
+++ b/lib/irb/workspace.rb
@@ -49,7 +49,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/lib/irb/workspace.rb#L49
           @binding = BINDING_QUEUE.pop
 
         when 3	# binding in function on TOPLEVEL_BINDING(default)
-          @binding = eval("self.class.remove_method(:irb_binding) if defined?(irb_binding); def irb_binding; private; binding; end; irb_binding",
+          @binding = eval("def irb_binding; private; binding; end; irb_binding",
                           TOPLEVEL_BINDING,
                           __FILE__,
                           __LINE__ - 3)
@@ -116,7 +116,11 @@ EOF https://github.com/ruby/ruby/blob/trunk/lib/irb/workspace.rb#L116
     end
 
     def code_around_binding
-      file, pos = @binding.source_location
+      if @binding.respond_to?(:source_location)
+        file, pos = @binding.source_location
+      else
+        file, pos = @binding.eval('[__FILE__, __LINE__]')
+      end
 
       if defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file]
         code = ::SCRIPT_LINES__[file].join('')
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index 4b18785..8439fd5 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -15,6 +15,11 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L15
     CYAN      = "\e[36m"
 
     def test_colorize_code
+      if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0')
+        assert_equal({}, IRB::Color::TOKEN_SEQ_EXPRS)
+        skip "this Ripper version is not supported"
+      end
+
       {
         "1" => "#{BLUE}#{BOLD (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]