aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-24 18:08:15 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-24 18:08:15 +0000
commit3711373e7395d96537b5a5ccad9ffb93d522711c (patch)
tree6e60acf1dff6953a87fc6ccb61137c962feac16f /lib
parentafb96c341aac18e3736d87b83a9944395ede0934 (diff)
downloadruby-3711373e7395d96537b5a5ccad9ffb93d522711c.tar.gz
lib/ostruct.rb: Use frozen literals.
Patch adapted from Espartaco Palma. [GH-1714] [Bug #14000] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/ostruct.rb27
1 files changed, 11 insertions, 16 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 2edb2edeb4..6cf0ecefc3 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -1,4 +1,4 @@
-# frozen_string_literal: false
+# frozen_string_literal: true
#
# = ostruct.rb: OpenStruct implementation
#
@@ -308,25 +308,20 @@ class OpenStruct
# Returns a string containing a detailed summary of the keys and values.
#
def inspect
- str = "#<#{self.class}"
-
ids = (Thread.current[InspectKey] ||= [])
if ids.include?(object_id)
- return str << ' ...>'
- end
-
- ids << object_id
- begin
- first = true
- for k,v in @table
- str << "," unless first
- first = false
- str << " #{k}=#{v.inspect}"
+ detail = ' ...'
+ else
+ ids << object_id
+ begin
+ detail = @table.map do |key, value|
+ " #{key}=#{value.inspect}"
+ end.join(',')
+ ensure
+ ids.pop
end
- return str << '>'
- ensure
- ids.pop
end
+ ['#<', self.class, detail, '>'].join
end
alias :to_s :inspect