sentry-ruby 0.3.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +102 -14
  3. metadata +41 -54
  4. data/.craft.yml +0 -19
  5. data/.gitignore +0 -11
  6. data/.rspec +0 -3
  7. data/.travis.yml +0 -6
  8. data/CHANGELOG.md +0 -31
  9. data/CODE_OF_CONDUCT.md +0 -74
  10. data/Gemfile +0 -16
  11. data/Rakefile +0 -8
  12. data/bin/console +0 -14
  13. data/bin/setup +0 -8
  14. data/lib/sentry/backtrace.rb +0 -128
  15. data/lib/sentry/benchmarks/benchmark_transport.rb +0 -14
  16. data/lib/sentry/breadcrumb/sentry_logger.rb +0 -87
  17. data/lib/sentry/breadcrumb.rb +0 -25
  18. data/lib/sentry/breadcrumb_buffer.rb +0 -47
  19. data/lib/sentry/client.rb +0 -80
  20. data/lib/sentry/configuration.rb +0 -387
  21. data/lib/sentry/core_ext/object/deep_dup.rb +0 -57
  22. data/lib/sentry/core_ext/object/duplicable.rb +0 -153
  23. data/lib/sentry/dsn.rb +0 -48
  24. data/lib/sentry/event.rb +0 -177
  25. data/lib/sentry/hub.rb +0 -137
  26. data/lib/sentry/interface.rb +0 -22
  27. data/lib/sentry/interfaces/exception.rb +0 -11
  28. data/lib/sentry/interfaces/request.rb +0 -95
  29. data/lib/sentry/interfaces/single_exception.rb +0 -14
  30. data/lib/sentry/interfaces/stacktrace.rb +0 -57
  31. data/lib/sentry/linecache.rb +0 -44
  32. data/lib/sentry/logger.rb +0 -20
  33. data/lib/sentry/rack/capture_exception.rb +0 -45
  34. data/lib/sentry/rack/tracing.rb +0 -39
  35. data/lib/sentry/rack.rb +0 -5
  36. data/lib/sentry/scope.rb +0 -214
  37. data/lib/sentry/span.rb +0 -155
  38. data/lib/sentry/transaction.rb +0 -113
  39. data/lib/sentry/transaction_event.rb +0 -29
  40. data/lib/sentry/transport/configuration.rb +0 -21
  41. data/lib/sentry/transport/dummy_transport.rb +0 -14
  42. data/lib/sentry/transport/http_transport.rb +0 -65
  43. data/lib/sentry/transport/state.rb +0 -40
  44. data/lib/sentry/transport.rb +0 -97
  45. data/lib/sentry/utils/exception_cause_chain.rb +0 -20
  46. data/lib/sentry/utils/real_ip.rb +0 -70
  47. data/lib/sentry/utils/request_id.rb +0 -16
  48. data/lib/sentry/version.rb +0 -3
  49. data/lib/sentry-ruby.rb +0 -123
  50. data/sentry-ruby.gemspec +0 -26
@@ -1,87 +0,0 @@
1
- require 'logger'
2
-
3
- module Sentry
4
- class Breadcrumb
5
- module SentryLogger
6
- LEVELS = {
7
- ::Logger::DEBUG => 'debug',
8
- ::Logger::INFO => 'info',
9
- ::Logger::WARN => 'warn',
10
- ::Logger::ERROR => 'error',
11
- ::Logger::FATAL => 'fatal'
12
- }.freeze
13
-
14
- def add(*args, &block)
15
- super
16
- add_breadcrumb(*args, &block)
17
- end
18
-
19
- def add_breadcrumb(severity, message = nil, progname = nil)
20
- # because the breadcrumbs now belongs to different Hub's Scope in different threads
21
- # we need to make sure the current thread's Hub has been set before adding breadcrumbs
22
- return unless Sentry.get_current_hub
23
-
24
- category = "logger"
25
-
26
- # this is because the nature of Ruby Logger class:
27
- #
28
- # when given 1 argument, the argument will become both message and progname
29
- #
30
- # ```
31
- # logger.info("foo")
32
- # # message == progname == "foo"
33
- # ```
34
- #
35
- # and to specify progname with a different message,
36
- # we need to pass the progname as the argument and pass the message as a proc
37
- #
38
- # ```
39
- # logger.info("progname") { "the message" }
40
- # ```
41
- #
42
- # so the condition below is to replicate the similar behavior
43
- if message.nil?
44
- if block_given?
45
- message = yield
46
- category = progname
47
- else
48
- message = progname
49
- end
50
- end
51
-
52
- return if ignored_logger?(progname) || message.empty?
53
-
54
- # some loggers will add leading/trailing space as they (incorrectly, mind you)
55
- # think of logging as a shortcut to std{out,err}
56
- message = message.to_s.strip
57
-
58
- last_crumb = current_breadcrumbs.peek
59
- # try to avoid dupes from logger broadcasts
60
- if last_crumb.nil? || last_crumb.message != message
61
- level = Sentry::Breadcrumb::SentryLogger::LEVELS.fetch(severity, nil)
62
- crumb = Sentry::Breadcrumb.new(
63
- level: level,
64
- category: category,
65
- message: message,
66
- type: severity >= 3 ? "error" : level
67
- )
68
-
69
- Sentry.add_breadcrumb(crumb)
70
- end
71
- end
72
-
73
- private
74
-
75
- def ignored_logger?(progname)
76
- progname == LOGGER_PROGNAME ||
77
- Sentry.configuration.exclude_loggers.include?(progname)
78
- end
79
-
80
- def current_breadcrumbs
81
- Sentry.get_current_scope.breadcrumbs
82
- end
83
- end
84
- end
85
- end
86
-
87
- ::Logger.send(:prepend, Sentry::Breadcrumb::SentryLogger)
@@ -1,25 +0,0 @@
1
- module Sentry
2
- class Breadcrumb
3
- attr_accessor :category, :data, :message, :level, :timestamp, :type
4
-
5
- def initialize(category: nil, data: nil, message: nil, timestamp: nil, level: nil, type: nil)
6
- @category = category
7
- @data = data || {}
8
- @level = level
9
- @message = message
10
- @timestamp = timestamp || Sentry.utc_now.to_i
11
- @type = type
12
- end
13
-
14
- def to_hash
15
- {
16
- :category => @category,
17
- :data => @data,
18
- :level => @level,
19
- :message => @message,
20
- :timestamp => @timestamp,
21
- :type => @type
22
- }
23
- end
24
- end
25
- end
@@ -1,47 +0,0 @@
1
- require "sentry/breadcrumb"
2
-
3
- module Sentry
4
- class BreadcrumbBuffer
5
- include Enumerable
6
-
7
- attr_accessor :buffer
8
-
9
- def initialize(size = 100)
10
- @buffer = Array.new(size)
11
- end
12
-
13
- def record(crumb)
14
- yield(crumb) if block_given?
15
- @buffer.slice!(0)
16
- @buffer << crumb
17
- end
18
-
19
- def members
20
- @buffer.compact
21
- end
22
-
23
- def peek
24
- members.last
25
- end
26
-
27
- def each(&block)
28
- members.each(&block)
29
- end
30
-
31
- def empty?
32
- members.none?
33
- end
34
-
35
- def to_hash
36
- {
37
- :values => members.map(&:to_hash)
38
- }
39
- end
40
-
41
- def dup
42
- copy = super
43
- copy.buffer = buffer.deep_dup
44
- copy
45
- end
46
- end
47
- end
data/lib/sentry/client.rb DELETED
@@ -1,80 +0,0 @@
1
- require "sentry/transport"
2
-
3
- module Sentry
4
- class Client
5
- attr_reader :transport, :configuration
6
-
7
- def initialize(configuration)
8
- @configuration = configuration
9
-
10
- if transport_class = configuration.transport.transport_class
11
- @transport = transport_class.new(configuration)
12
- else
13
- @transport =
14
- case configuration.dsn&.scheme
15
- when 'http', 'https'
16
- HTTPTransport.new(configuration)
17
- else
18
- DummyTransport.new(configuration)
19
- end
20
- end
21
- end
22
-
23
- def capture_event(event, scope, hint = nil)
24
- scope.apply_to_event(event, hint)
25
-
26
- if configuration.async?
27
- begin
28
- # We have to convert to a JSON-like hash, because background job
29
- # processors (esp ActiveJob) may not like weird types in the event hash
30
- configuration.async.call(event.to_json_compatible)
31
- rescue => e
32
- configuration.logger.error(LOGGER_PROGNAME) { "async event sending failed: #{e.message}" }
33
- send_event(event, hint)
34
- end
35
- else
36
- send_event(event, hint)
37
- end
38
-
39
- event
40
- end
41
-
42
- def event_from_exception(exception)
43
- return unless @configuration.exception_class_allowed?(exception)
44
-
45
- Event.new(configuration: configuration).tap do |event|
46
- event.add_exception_interface(exception)
47
- end
48
- end
49
-
50
- def event_from_message(message)
51
- Event.new(configuration: configuration, message: message)
52
- end
53
-
54
- def event_from_transaction(transaction)
55
- TransactionEvent.new(configuration: configuration).tap do |event|
56
- event.transaction = transaction.name
57
- event.contexts.merge!(trace: transaction.get_trace_context)
58
- event.timestamp = transaction.timestamp
59
- event.start_timestamp = transaction.start_timestamp
60
-
61
- finished_spans = transaction.span_recorder.spans.select { |span| span.timestamp && span != transaction }
62
- event.spans = finished_spans.map(&:to_hash)
63
- end
64
- end
65
-
66
- def send_event(event, hint = nil)
67
- return false unless configuration.sending_allowed?
68
-
69
- event = configuration.before_send.call(event, hint) if configuration.before_send
70
- if event.nil?
71
- configuration.logger.info(LOGGER_PROGNAME) { "Discarded event because before_send returned nil" }
72
- return
73
- end
74
-
75
- transport.send_event(event)
76
-
77
- event
78
- end
79
- end
80
- end
@@ -1,387 +0,0 @@
1
- require "sentry/utils/exception_cause_chain"
2
- require "sentry/dsn"
3
- require "sentry/transport/configuration"
4
- require "sentry/linecache"
5
-
6
- module Sentry
7
- class Configuration
8
- # Directories to be recognized as part of your app. e.g. if you
9
- # have an `engines` dir at the root of your project, you may want
10
- # to set this to something like /(app|config|engines|lib)/
11
- attr_accessor :app_dirs_pattern
12
-
13
- # Provide an object that responds to `call` to send events asynchronously.
14
- # E.g.: lambda { |event| Thread.new { Sentry.send_event(event) } }
15
- attr_reader :async
16
- alias async? async
17
-
18
- # a proc/lambda that takes an array of stack traces
19
- # it'll be used to silence (reduce) backtrace of the exception
20
- #
21
- # for example:
22
- #
23
- # ```ruby
24
- # Sentry.configuration.backtrace_cleanup_callback = lambda do |backtrace|
25
- # Rails.backtrace_cleaner.clean(backtrace)
26
- # end
27
- # ```
28
- #
29
- attr_accessor :backtrace_cleanup_callback
30
-
31
- # Optional Proc, called before sending an event to the server/
32
- # E.g.: lambda { |event| event }
33
- # E.g.: lambda { |event| nil }
34
- # E.g.: lambda { |event|
35
- # event[:message] = 'a'
36
- # event
37
- # }
38
- attr_reader :before_send
39
-
40
- # An array of breadcrumbs loggers to be used. Available options are:
41
- # - :sentry_logger
42
- # - :active_support_logger
43
- attr_reader :breadcrumbs_logger
44
-
45
- # Number of lines of code context to capture, or nil for none
46
- attr_accessor :context_lines
47
-
48
- # RACK_ENV by default.
49
- attr_reader :environment
50
-
51
- # the dsn value, whether it's set via `config.dsn=` or `ENV["SENTRY_DSN"]`
52
- attr_reader :dsn
53
-
54
- # Whitelist of enabled_environments that will send notifications to Sentry. Array of Strings.
55
- attr_accessor :enabled_environments
56
-
57
- # Logger 'progname's to exclude from breadcrumbs
58
- attr_accessor :exclude_loggers
59
-
60
- # Array of exception classes that should never be sent. See IGNORE_DEFAULT.
61
- # You should probably append to this rather than overwrite it.
62
- attr_accessor :excluded_exceptions
63
-
64
- # Boolean to check nested exceptions when deciding if to exclude. Defaults to false
65
- attr_accessor :inspect_exception_causes_for_exclusion
66
- alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
67
-
68
- # You may provide your own LineCache for matching paths with source files.
69
- # This may be useful if you need to get source code from places other than
70
- # the disk. See Sentry::LineCache for the required interface you must implement.
71
- attr_accessor :linecache
72
-
73
- # Logger used by Sentry. In Rails, this is the Rails logger, otherwise
74
- # Sentry provides its own Sentry::Logger.
75
- attr_accessor :logger
76
-
77
- # Project directory root for in_app detection. Could be Rails root, etc.
78
- # Set automatically for Rails.
79
- attr_reader :project_root
80
-
81
- # Array of rack env parameters to be included in the event sent to sentry.
82
- attr_accessor :rack_env_whitelist
83
-
84
- # Release tag to be passed with every event sent to Sentry.
85
- # We automatically try to set this to a git SHA or Capistrano release.
86
- attr_accessor :release
87
-
88
- # The sampling factor to apply to events. A value of 0.0 will not send
89
- # any events, and a value of 1.0 will send 100% of events.
90
- attr_accessor :sample_rate
91
-
92
- # Include module versions in reports - boolean.
93
- attr_accessor :send_modules
94
-
95
- # When send_default_pii's value is false (default), sensitive information like
96
- # - user ip
97
- # - user cookie
98
- # - request body
99
- # will not be sent to Sentry.
100
- attr_accessor :send_default_pii
101
-
102
- attr_accessor :server_name
103
-
104
- # Return a Transport::Configuration object for transport-related configurations.
105
- attr_reader :transport
106
-
107
- # Take a float between 0.0 and 1.0 as the sample rate for tracing events (transactions).
108
- attr_accessor :traces_sample_rate
109
-
110
- # Take a Proc that controls the sample rate for every tracing event, e.g.
111
- # ```
112
- # lambda do |tracing_context|
113
- # # tracing_context[:transaction_context] contains the information about the transaction
114
- # # tracing_context[:parent_sampled] contains the transaction's parent's sample decision
115
- # true # return value can be a boolean or a float between 0.0 and 1.0
116
- # end
117
- # ```
118
- attr_accessor :traces_sampler
119
-
120
- # these are not config options
121
- attr_reader :errors, :gem_specs
122
-
123
- # Most of these errors generate 4XX responses. In general, Sentry clients
124
- # only automatically report 5xx responses.
125
- IGNORE_DEFAULT = [
126
- 'CGI::Session::CookieStore::TamperedWithCookie',
127
- 'Mongoid::Errors::DocumentNotFound',
128
- 'Rack::QueryParser::InvalidParameterError',
129
- 'Rack::QueryParser::ParameterTypeError',
130
- 'Sinatra::NotFound'
131
- ].freeze
132
-
133
- RACK_ENV_WHITELIST_DEFAULT = %w(
134
- REMOTE_ADDR
135
- SERVER_NAME
136
- SERVER_PORT
137
- ).freeze
138
-
139
- HEROKU_DYNO_METADATA_MESSAGE = "You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\
140
- "release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`".freeze
141
-
142
- LOG_PREFIX = "** [Sentry] ".freeze
143
- MODULE_SEPARATOR = "::".freeze
144
-
145
- AVAILABLE_BREADCRUMBS_LOGGERS = [:sentry_logger, :active_support_logger].freeze
146
-
147
- def initialize
148
- self.async = false
149
- self.breadcrumbs_logger = []
150
- self.context_lines = 3
151
- self.environment = environment_from_env
152
- self.enabled_environments = []
153
- self.exclude_loggers = []
154
- self.excluded_exceptions = IGNORE_DEFAULT.dup
155
- self.inspect_exception_causes_for_exclusion = false
156
- self.linecache = ::Sentry::LineCache.new
157
- self.logger = ::Sentry::Logger.new(STDOUT)
158
- self.project_root = detect_project_root
159
-
160
- self.release = detect_release
161
- self.sample_rate = 1.0
162
- self.send_modules = true
163
- self.send_default_pii = false
164
- self.dsn = ENV['SENTRY_DSN']
165
- self.server_name = server_name_from_env
166
-
167
- self.before_send = false
168
- self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
169
-
170
- @transport = Transport::Configuration.new
171
- @gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)
172
- post_initialization_callback
173
- end
174
-
175
- def dsn=(value)
176
- return if value.nil? || value.empty?
177
-
178
- @dsn = DSN.new(value)
179
- end
180
-
181
- alias server= dsn=
182
-
183
-
184
- def async=(value)
185
- unless value == false || value.respond_to?(:call)
186
- raise(ArgumentError, "async must be callable (or false to disable)")
187
- end
188
-
189
- @async = value
190
- end
191
-
192
- def breadcrumbs_logger=(logger)
193
- loggers =
194
- if logger.is_a?(Array)
195
- logger
196
- else
197
- unless AVAILABLE_BREADCRUMBS_LOGGERS.include?(logger)
198
- raise Sentry::Error, "Unsupported breadcrumbs logger. Supported loggers: #{AVAILABLE_BREADCRUMBS_LOGGERS}"
199
- end
200
-
201
- Array(logger)
202
- end
203
-
204
- require "sentry/breadcrumb/sentry_logger" if loggers.include?(:sentry_logger)
205
-
206
- @breadcrumbs_logger = logger
207
- end
208
-
209
- def before_send=(value)
210
- unless value == false || value.respond_to?(:call)
211
- raise ArgumentError, "before_send must be callable (or false to disable)"
212
- end
213
-
214
- @before_send = value
215
- end
216
-
217
- def environment=(environment)
218
- @environment = environment.to_s
219
- end
220
-
221
- def sending_allowed?
222
- @errors = []
223
-
224
- valid? &&
225
- capture_in_environment? &&
226
- sample_allowed?
227
- end
228
-
229
- def error_messages
230
- @errors = [@errors[0]] + @errors[1..-1].map(&:downcase) # fix case of all but first
231
- @errors.join(", ")
232
- end
233
-
234
- def project_root=(root_dir)
235
- @project_root = root_dir
236
- end
237
-
238
- def exception_class_allowed?(exc)
239
- if exc.is_a?(Sentry::Error)
240
- # Try to prevent error reporting loops
241
- logger.debug(LOGGER_PROGNAME) { "Refusing to capture Sentry error: #{exc.inspect}" }
242
- false
243
- elsif excluded_exception?(exc)
244
- logger.debug(LOGGER_PROGNAME) { "User excluded error: #{exc.inspect}" }
245
- false
246
- else
247
- true
248
- end
249
- end
250
-
251
- def enabled_in_current_env?
252
- enabled_environments.empty? || enabled_environments.include?(environment)
253
- end
254
-
255
- def tracing_enabled?
256
- !!((@traces_sample_rate && @traces_sample_rate > 0.0) || @traces_sampler)
257
- end
258
-
259
- private
260
-
261
- def detect_project_root
262
- if defined? Rails.root # we are in a Rails application
263
- Rails.root.to_s
264
- else
265
- Dir.pwd
266
- end
267
- end
268
-
269
- def detect_release
270
- detect_release_from_env ||
271
- detect_release_from_git ||
272
- detect_release_from_capistrano ||
273
- detect_release_from_heroku
274
- rescue => e
275
- logger.error(LOGGER_PROGNAME) { "Error detecting release: #{e.message}" }
276
- end
277
-
278
- def excluded_exception?(incoming_exception)
279
- excluded_exception_classes.any? do |excluded_exception|
280
- matches_exception?(excluded_exception, incoming_exception)
281
- end
282
- end
283
-
284
- def excluded_exception_classes
285
- @excluded_exception_classes ||= excluded_exceptions.map { |e| get_exception_class(e) }
286
- end
287
-
288
- def get_exception_class(x)
289
- x.is_a?(Module) ? x : safe_const_get(x)
290
- end
291
-
292
- def matches_exception?(excluded_exception_class, incoming_exception)
293
- if inspect_exception_causes_for_exclusion?
294
- Sentry::Utils::ExceptionCauseChain.exception_to_array(incoming_exception).any? { |cause| excluded_exception_class === cause }
295
- else
296
- excluded_exception_class === incoming_exception
297
- end
298
- end
299
-
300
- def safe_const_get(x)
301
- x = x.to_s unless x.is_a?(String)
302
- Object.const_get(x)
303
- rescue NameError # There's no way to safely ask if a constant exist for an unknown string
304
- nil
305
- end
306
-
307
- def detect_release_from_heroku
308
- return unless running_on_heroku?
309
- return if ENV['CI']
310
- logger.warn(LOGGER_PROGNAME) { HEROKU_DYNO_METADATA_MESSAGE } && return unless ENV['HEROKU_SLUG_COMMIT']
311
-
312
- ENV['HEROKU_SLUG_COMMIT']
313
- end
314
-
315
- def running_on_heroku?
316
- File.directory?("/etc/heroku")
317
- end
318
-
319
- def detect_release_from_capistrano
320
- revision_file = File.join(project_root, 'REVISION')
321
- revision_log = File.join(project_root, '..', 'revisions.log')
322
-
323
- if File.exist?(revision_file)
324
- File.read(revision_file).strip
325
- elsif File.exist?(revision_log)
326
- File.open(revision_log).to_a.last.strip.sub(/.*as release ([0-9]+).*/, '\1')
327
- end
328
- end
329
-
330
- def detect_release_from_git
331
- Sentry.sys_command("git rev-parse --short HEAD") if File.directory?(".git")
332
- end
333
-
334
- def detect_release_from_env
335
- ENV['SENTRY_RELEASE']
336
- end
337
-
338
- def capture_in_environment?
339
- return true if enabled_in_current_env?
340
-
341
- @errors << "Not configured to send/capture in environment '#{environment}'"
342
- false
343
- end
344
-
345
- def valid?
346
- if @dsn&.valid?
347
- true
348
- else
349
- @errors << "DSN not set or not valid"
350
- false
351
- end
352
- end
353
-
354
- def sample_allowed?
355
- return true if sample_rate == 1.0
356
-
357
- if Random::DEFAULT.rand >= sample_rate
358
- @errors << "Excluded by random sample"
359
- false
360
- else
361
- true
362
- end
363
- end
364
-
365
- # Try to resolve the hostname to an FQDN, but fall back to whatever
366
- # the load name is.
367
- def resolve_hostname
368
- Socket.gethostname ||
369
- Socket.gethostbyname(hostname).first rescue server_name
370
- end
371
-
372
- def environment_from_env
373
- ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
374
- end
375
-
376
- def server_name_from_env
377
- if running_on_heroku?
378
- ENV['DYNO']
379
- else
380
- resolve_hostname
381
- end
382
- end
383
-
384
- # allow extensions to extend the Configuration class
385
- def post_initialization_callback; end
386
- end
387
- end
@@ -1,57 +0,0 @@
1
- require 'sentry/core_ext/object/duplicable'
2
-
3
- #########################################
4
- # This file was copied from Rails 5.2 #
5
- #########################################
6
-
7
- class Object
8
- # Returns a deep copy of object if it's duplicable. If it's
9
- # not duplicable, returns +self+.
10
- #
11
- # object = Object.new
12
- # dup = object.deep_dup
13
- # dup.instance_variable_set(:@a, 1)
14
- #
15
- # object.instance_variable_defined?(:@a) # => false
16
- # dup.instance_variable_defined?(:@a) # => true
17
- def deep_dup
18
- duplicable? ? dup : self
19
- end
20
- end
21
-
22
- class Array
23
- # Returns a deep copy of array.
24
- #
25
- # array = [1, [2, 3]]
26
- # dup = array.deep_dup
27
- # dup[1][2] = 4
28
- #
29
- # array[1][2] # => nil
30
- # dup[1][2] # => 4
31
- def deep_dup
32
- map(&:deep_dup)
33
- end
34
- end
35
-
36
- class Hash
37
- # Returns a deep copy of hash.
38
- #
39
- # hash = { a: { b: 'b' } }
40
- # dup = hash.deep_dup
41
- # dup[:a][:c] = 'c'
42
- #
43
- # hash[:a][:c] # => nil
44
- # dup[:a][:c] # => "c"
45
- def deep_dup
46
- hash = dup
47
- each_pair do |key, value|
48
- if key.frozen? && ::String === key
49
- hash[key] = value.deep_dup
50
- else
51
- hash.delete(key)
52
- hash[key.deep_dup] = value.deep_dup
53
- end
54
- end
55
- hash
56
- end
57
- end