summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2019-04-28 21:51:35 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-04-28 21:51:37 +0900
commitf2d7ba6a7473b408002c90b77b021fc837f93561 (patch)
tree74c9b0baba1772685f83b6aa8378e7a6ef1584fb
parent13abf5519a8c00ac2b05409e667c58f05c75123a (diff)
make sync-default-gems GEM=irb
from https://github.com/ruby/irb/commit/e8e79d569ed59fe4ed4fbca968917ce799f02a5e. This colorizes Range object on IRB inspect.
-rw-r--r--lib/irb/color.rb12
-rw-r--r--test/irb/test_color.rb1
2 files changed, 7 insertions, 6 deletions
diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index aec66cd63e..7af7118849 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -47,17 +47,17 @@ module IRB # :nodoc:
end
def inspect_colorable?(obj)
- if obj.is_a?(Module) && obj.name
- return true
- end
-
case obj
+ when String, Symbol, Regexp, Integer, Float, FalseClass, TrueClass, NilClass
+ true
when Hash
obj.all? { |k, v| inspect_colorable?(k) && inspect_colorable?(v) }
when Array
obj.all? { |o| inspect_colorable?(o) }
- when String, Symbol, Regexp, Integer, Float, FalseClass, TrueClass, NilClass
- true
+ when Range
+ inspect_colorable?(obj.begin) && inspect_colorable?(obj.end)
+ when Module
+ !obj.name.nil?
else
false
end
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index e6186efed2..3305c2414a 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -44,6 +44,7 @@ module TestIRB
['foo', :bar] => true,
{ a: 4 } => true,
/reg/ => true,
+ (1..3) => true,
Object.new => false,
Struct => true,
Test => true,