activesupport 8.0.2 → 8.0.5.2

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +175 -1
  3. data/README.rdoc +1 -1
  4. data/lib/active_support/broadcast_logger.rb +46 -59
  5. data/lib/active_support/cache/mem_cache_store.rb +16 -15
  6. data/lib/active_support/cache/redis_cache_store.rb +1 -1
  7. data/lib/active_support/cache.rb +1 -0
  8. data/lib/active_support/core_ext/benchmark.rb +1 -0
  9. data/lib/active_support/core_ext/class/attribute.rb +8 -6
  10. data/lib/active_support/core_ext/date_time/conversions.rb +4 -2
  11. data/lib/active_support/core_ext/enumerable.rb +16 -4
  12. data/lib/active_support/core_ext/object/json.rb +1 -1
  13. data/lib/active_support/core_ext/object/to_query.rb +2 -1
  14. data/lib/active_support/core_ext/object/try.rb +2 -2
  15. data/lib/active_support/core_ext/range/overlap.rb +3 -3
  16. data/lib/active_support/core_ext/range/sole.rb +17 -0
  17. data/lib/active_support/core_ext/range.rb +1 -0
  18. data/lib/active_support/core_ext/string/filters.rb +3 -3
  19. data/lib/active_support/core_ext/string/inflections.rb +1 -1
  20. data/lib/active_support/core_ext/string/multibyte.rb +2 -2
  21. data/lib/active_support/core_ext/string/output_safety.rb +3 -1
  22. data/lib/active_support/current_attributes.rb +13 -6
  23. data/lib/active_support/delegation.rb +25 -42
  24. data/lib/active_support/file_update_checker.rb +1 -1
  25. data/lib/active_support/gem_version.rb +2 -2
  26. data/lib/active_support/hash_with_indifferent_access.rb +20 -17
  27. data/lib/active_support/inflector/inflections.rb +2 -1
  28. data/lib/active_support/inflector/methods.rb +5 -21
  29. data/lib/active_support/isolated_execution_state.rb +4 -2
  30. data/lib/active_support/json/decoding.rb +4 -2
  31. data/lib/active_support/lazy_load_hooks.rb +1 -1
  32. data/lib/active_support/logger_thread_safe_level.rb +6 -3
  33. data/lib/active_support/message_pack/extensions.rb +1 -1
  34. data/lib/active_support/notifications/instrumenter.rb +1 -1
  35. data/lib/active_support/number_helper/number_converter.rb +1 -1
  36. data/lib/active_support/number_helper/number_to_delimited_converter.rb +17 -2
  37. data/lib/active_support/test_case.rb +6 -0
  38. data/lib/active_support/testing/assertions.rb +8 -3
  39. data/lib/active_support/testing/autorun.rb +5 -0
  40. data/lib/active_support/testing/parallelization/server.rb +15 -2
  41. data/lib/active_support/testing/parallelization/worker.rb +7 -3
  42. data/lib/active_support/testing/parallelization.rb +12 -1
  43. data/lib/active_support/xml_mini.rb +2 -0
  44. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f094945c33f1c6e036f987c0cc7405a0146f0c800635e1fc16d8a1c34910cb7
4
- data.tar.gz: 9ffe8729fffcae283965435a590eb7db596a43fa39c8565e814abab6e16e0444
3
+ metadata.gz: 22241404cc02e580fd1591eae63cc0ba8bbab2603e9d48e6baa6cefa4bbd6f1d
4
+ data.tar.gz: f62c817eb1ab3a3e9a3fa37d6cefabe0d52f8ac7da6de2bf9dcd0812d230eede
5
5
  SHA512:
6
- metadata.gz: a391e85fc1235084e201abc2736139578767397fa4a503573e82c5f7f339e13d13b5702302ff37176a26a8d80203fc914682e40c570d933aa282e2fb92f26e76
7
- data.tar.gz: 6adf2e0b528f17bcd51373d8e627c4ec77de8967c968fdab89fb2bac11952bf98f5ffb6910cdf372cf57bd7929f539808dc783160b0456a803783264421016ce
6
+ metadata.gz: ef9a83ed926881ac15c0f83c7786a439e79d21c3c3cbc0e72d9a2f39be2995f28bf4c62b78b1deaa079face57ed15b10200d10384f1f3dcef649b153acbf3dff
7
+ data.tar.gz: ec380533afadf6d311e522744467722aefc8575776fd1b9b8a686f645f6fcb2b4468826d5c87998e069a2ba2b7a7445adeefac43fae6a06fa181b00b5b6999bc
data/CHANGELOG.md CHANGED
@@ -1,4 +1,178 @@
1
- ## Rails 8.0.2 (March 12, 2025) ##
1
+ ## Rails 8.0.5.2 (November 03, 2026) ##
2
+
3
+ * `ActiveSupport::Inflector#safe_constantize` matches the constant name in a
4
+ `LoadError` message as a literal string instead of building a `Regexp`
5
+ from it.
6
+
7
+ The name's segments were interpolated unescaped into the pattern, so input
8
+ that reaches `safe_constantize`, such as the channel identifier in an Action
9
+ Cable subscribe command, chose the source passed to the regexp compiler.
10
+
11
+ [GHSA-8474-xrp6-wh69]
12
+
13
+ *Jeremy Daer*
14
+
15
+ ## Rails 8.0.5.1 (July 29, 2026) ##
16
+
17
+ * No changes.
18
+
19
+
20
+ ## Rails 8.0.5 (March 24, 2026) ##
21
+
22
+ * Fix inflections to better handle overlapping acronyms.
23
+
24
+ ```ruby
25
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
26
+ inflect.acronym "USD"
27
+ inflect.acronym "USDC"
28
+ end
29
+
30
+ "USDC".underscore # => "usdc"
31
+ ```
32
+
33
+ *Said Kaldybaev*
34
+
35
+ * Silence Dalli 4.0+ warning when using `ActiveSupport::Cache::MemCacheStore`.
36
+
37
+ *zzak*
38
+
39
+ * Make `delegate` and `delegate_missing_to` work in BasicObject subclasses.
40
+
41
+ *Rafael Mendonça França*
42
+
43
+ * Fix `ActiveSupport::Inflector.humanize` with international characters.
44
+
45
+ ```ruby
46
+ ActiveSupport::Inflector.humanize("áÉÍÓÚ") # => "Áéíóú"
47
+ ActiveSupport::Inflector.humanize("аБВГДЕ") # => "Абвгде"
48
+ ```
49
+
50
+ *Jose Luis Duran*
51
+
52
+
53
+ ## Rails 8.0.4.1 (March 23, 2026) ##
54
+
55
+ * Reject scientific notation in NumberConverter
56
+
57
+ [CVE-2026-33176]
58
+
59
+ *Jean Boussier*
60
+
61
+ * Fix `SafeBuffer#%` to preserve unsafe status
62
+
63
+ [CVE-2026-33170]
64
+
65
+ *Jean Boussier*
66
+
67
+ * Improve performance of NumberToDelimitedConverter
68
+
69
+ [CVE-2026-33169]
70
+
71
+ *Jean Boussier*
72
+
73
+
74
+ ## Rails 8.0.4 (October 28, 2025) ##
75
+
76
+ * Fix `Enumerable#sole` to return the full tuple instead of just the first element of the tuple.
77
+
78
+ *Olivier Bellone*
79
+
80
+ * Fix parallel tests hanging when worker processes die abruptly.
81
+
82
+ Previously, if a worker process was killed (e.g., OOM killed, `kill -9`) during parallel
83
+ test execution, the test suite would hang forever waiting for the dead worker.
84
+
85
+ *Joshua Young*
86
+
87
+ * Fix `NameError` when `class_attribute` is defined on instance singleton classes.
88
+
89
+ Previously, calling `class_attribute` on an instance's singleton class would raise
90
+ a `NameError` when accessing the attribute through the instance.
91
+
92
+ ```ruby
93
+ object = MyClass.new
94
+ object.singleton_class.class_attribute :foo, default: "bar"
95
+ object.foo # previously raised NameError, now returns "bar"
96
+ ```
97
+
98
+ *Joshua Young*
99
+
100
+
101
+ ## Rails 8.0.3 (September 22, 2025) ##
102
+
103
+ * `ActiveSupport::FileUpdateChecker` does not depend on `Time.now` to prevent unnecessary reloads with time travel test helpers
104
+
105
+ *Jan Grodowski*
106
+
107
+ * Fix `ActiveSupport::BroadcastLogger` from executing a block argument for each logger (tagged, info, etc.).
108
+
109
+ *Jared Armstrong*
110
+
111
+ * Make `ActiveSupport::Logger` `#freeze`-friendly.
112
+
113
+ *Joshua Young*
114
+
115
+ * Fix `ActiveSupport::HashWithIndifferentAccess#transform_keys!` removing defaults.
116
+
117
+ *Hartley McGuire*
118
+
119
+ * Fix `ActiveSupport::HashWithIndifferentAccess#tranform_keys!` to handle collisions.
120
+
121
+ If the transformation would result in a key equal to another not yet transformed one,
122
+ it would result in keys being lost.
123
+
124
+ Before:
125
+
126
+ ```ruby
127
+ >> {a: 1, b: 2}.with_indifferent_access.transform_keys!(&:succ)
128
+ => {"c" => 1}
129
+ ```
130
+
131
+ After:
132
+
133
+ ```ruby
134
+ >> {a: 1, b: 2}.with_indifferent_access.transform_keys!(&:succ)
135
+ => {"b" => 1, "c" => 2}
136
+ ```
137
+
138
+ *Jason T Johnson*, *Jean Boussier*
139
+
140
+ **Note on overwrite precedence:**
141
+
142
+ This fix also changed the overwrite precedence when distinct keys are transformed into the same key.
143
+ The later key now overwrites the earlier one (matching standard Ruby `Hash` behavior).
144
+ Previously, the earlier key's value was preserved.
145
+
146
+ Before:
147
+
148
+ ```ruby
149
+ >> {XY: 1, xy: 2}.with_indifferent_access.transform_keys!(&:downcase)
150
+ => {"xy"=>1}
151
+ ```
152
+
153
+ After:
154
+
155
+ ```ruby
156
+ >> {XY: 1, xy: 2}.with_indifferent_access.transform_keys!(&:downcase)
157
+ => {"xy"=>2}
158
+ ```
159
+
160
+ * Fix `ActiveSupport::Cache::MemCacheStore#read_multi` to handle network errors.
161
+
162
+ This method specifically wasn't handling network errors like other codepaths.
163
+
164
+ *Alessandro Dal Grande*
165
+
166
+ * Fix configuring `RedisCacheStore` with `raw: true`.
167
+
168
+ *fatkodima*
169
+
170
+ * Fix `Enumerable#sole` for infinite collections.
171
+
172
+ *fatkodima*
173
+
174
+
175
+ ## Rails 8.0.2.1 (August 13, 2025) ##
2
176
 
3
177
  * No changes.
4
178
 
data/README.rdoc CHANGED
@@ -35,6 +35,6 @@ Bug reports for the Ruby on \Rails project can be filed here:
35
35
 
36
36
  * https://github.com/rails/rails/issues
37
37
 
38
- Feature requests should be discussed on the rails-core mailing list here:
38
+ Feature requests should be discussed on the rubyonrails-core forum here:
39
39
 
40
40
  * https://discuss.rubyonrails.org/c/rubyonrails-core
@@ -76,7 +76,6 @@ module ActiveSupport
76
76
 
77
77
  # Returns all the logger that are part of this broadcast.
78
78
  attr_reader :broadcasts
79
- attr_reader :formatter
80
79
  attr_accessor :progname
81
80
 
82
81
  def initialize(*loggers)
@@ -105,62 +104,36 @@ module ActiveSupport
105
104
  @broadcasts.delete(logger)
106
105
  end
107
106
 
108
- def level
109
- @broadcasts.map(&:level).min
110
- end
111
-
112
- def <<(message)
113
- dispatch { |logger| logger.<<(message) }
114
- end
115
-
116
- def add(...)
117
- dispatch { |logger| logger.add(...) }
118
- end
119
- alias_method :log, :add
120
-
121
- def debug(...)
122
- dispatch { |logger| logger.debug(...) }
123
- end
124
-
125
- def info(...)
126
- dispatch { |logger| logger.info(...) }
127
- end
128
-
129
- def warn(...)
130
- dispatch { |logger| logger.warn(...) }
131
- end
132
-
133
- def error(...)
134
- dispatch { |logger| logger.error(...) }
135
- end
136
-
137
- def fatal(...)
138
- dispatch { |logger| logger.fatal(...) }
139
- end
140
-
141
- def unknown(...)
142
- dispatch { |logger| logger.unknown(...) }
107
+ def local_level=(level)
108
+ @broadcasts.each do |logger|
109
+ logger.local_level = level if logger.respond_to?(:local_level=)
110
+ end
143
111
  end
144
112
 
145
- def formatter=(formatter)
146
- dispatch { |logger| logger.formatter = formatter }
147
-
148
- @formatter = formatter
149
- end
113
+ def local_level
114
+ loggers = @broadcasts.select { |logger| logger.respond_to?(:local_level) }
150
115
 
151
- def level=(level)
152
- dispatch { |logger| logger.level = level }
116
+ loggers.map do |logger|
117
+ logger.local_level
118
+ end.first
153
119
  end
154
- alias_method :sev_threshold=, :level=
155
120
 
156
- def local_level=(level)
157
- dispatch do |logger|
158
- logger.local_level = level if logger.respond_to?(:local_level=)
159
- end
121
+ LOGGER_METHODS = %w[
122
+ << log add debug info warn error fatal unknown
123
+ level= sev_threshold= close
124
+ formatter formatter=
125
+ ] # :nodoc:
126
+ LOGGER_METHODS.each do |method|
127
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
128
+ def #{method}(...)
129
+ dispatch(:#{method}, ...)
130
+ end
131
+ RUBY
160
132
  end
161
133
 
162
- def close
163
- dispatch { |logger| logger.close }
134
+ # Returns the lowest level of all the loggers in the broadcast.
135
+ def level
136
+ @broadcasts.map(&:level).min
164
137
  end
165
138
 
166
139
  # True if the log level allows entries with severity +Logger::DEBUG+ to be written
@@ -171,7 +144,7 @@ module ActiveSupport
171
144
 
172
145
  # Sets the log level to +Logger::DEBUG+ for the whole broadcast.
173
146
  def debug!
174
- dispatch { |logger| logger.debug! }
147
+ dispatch(:debug!)
175
148
  end
176
149
 
177
150
  # True if the log level allows entries with severity +Logger::INFO+ to be written
@@ -182,7 +155,7 @@ module ActiveSupport
182
155
 
183
156
  # Sets the log level to +Logger::INFO+ for the whole broadcast.
184
157
  def info!
185
- dispatch { |logger| logger.info! }
158
+ dispatch(:info!)
186
159
  end
187
160
 
188
161
  # True if the log level allows entries with severity +Logger::WARN+ to be written
@@ -193,7 +166,7 @@ module ActiveSupport
193
166
 
194
167
  # Sets the log level to +Logger::WARN+ for the whole broadcast.
195
168
  def warn!
196
- dispatch { |logger| logger.warn! }
169
+ dispatch(:warn!)
197
170
  end
198
171
 
199
172
  # True if the log level allows entries with severity +Logger::ERROR+ to be written
@@ -204,7 +177,7 @@ module ActiveSupport
204
177
 
205
178
  # Sets the log level to +Logger::ERROR+ for the whole broadcast.
206
179
  def error!
207
- dispatch { |logger| logger.error! }
180
+ dispatch(:error!)
208
181
  end
209
182
 
210
183
  # True if the log level allows entries with severity +Logger::FATAL+ to be written
@@ -215,21 +188,35 @@ module ActiveSupport
215
188
 
216
189
  # Sets the log level to +Logger::FATAL+ for the whole broadcast.
217
190
  def fatal!
218
- dispatch { |logger| logger.fatal! }
191
+ dispatch(:fatal!)
219
192
  end
220
193
 
221
194
  def initialize_copy(other)
222
195
  @broadcasts = []
223
196
  @progname = other.progname.dup
224
- @formatter = other.formatter.dup
225
197
 
226
198
  broadcast_to(*other.broadcasts.map(&:dup))
227
199
  end
228
200
 
229
201
  private
230
- def dispatch(&block)
231
- @broadcasts.each { |logger| block.call(logger) }
232
- true
202
+ def dispatch(method, *args, **kwargs, &block)
203
+ if block_given?
204
+ # Maintain semantics that the first logger yields the block
205
+ # as normal, but subsequent loggers won't re-execute the block.
206
+ # Instead, the initial result is immediately returned.
207
+ called, result = false, nil
208
+ block = proc { |*args, **kwargs|
209
+ if called then result
210
+ else
211
+ called = true
212
+ result = yield(*args, **kwargs)
213
+ end
214
+ }
215
+ end
216
+
217
+ @broadcasts.map { |logger|
218
+ logger.send(method, *args, **kwargs, &block)
219
+ }.first
233
220
  end
234
221
 
235
222
  def method_missing(name, ...)
@@ -60,7 +60,7 @@ module ActiveSupport
60
60
  pool_options = retrieve_pool_options(options)
61
61
 
62
62
  if pool_options
63
- ConnectionPool.new(pool_options) { Dalli::Client.new(addresses, options.merge(threadsafe: false)) }
63
+ ConnectionPool.new(**pool_options) { Dalli::Client.new(addresses, options.merge(threadsafe: false)) }
64
64
  else
65
65
  Dalli::Client.new(addresses, options)
66
66
  end
@@ -90,6 +90,9 @@ module ActiveSupport
90
90
  # The value "compress: false" prevents duplicate compression within Dalli.
91
91
  @mem_cache_options[:compress] = false
92
92
  (OVERRIDDEN_OPTIONS - %i(compress)).each { |name| @mem_cache_options.delete(name) }
93
+ # Set the default serializer for Dalli to prevent warning about
94
+ # inheriting the default serializer.
95
+ @mem_cache_options[:serializer] = Marshal
93
96
  @data = self.class.build_mem_cache(*(addresses + [@mem_cache_options]))
94
97
  end
95
98
 
@@ -212,26 +215,24 @@ module ActiveSupport
212
215
  def read_multi_entries(names, **options)
213
216
  keys_to_names = names.index_by { |name| normalize_key(name, options) }
214
217
 
215
- raw_values = begin
216
- @data.with { |c| c.get_multi(keys_to_names.keys) }
217
- rescue Dalli::UnmarshalError
218
- {}
219
- end
218
+ rescue_error_with({}) do
219
+ raw_values = @data.with { |c| c.get_multi(keys_to_names.keys) }
220
220
 
221
- values = {}
221
+ values = {}
222
222
 
223
- raw_values.each do |key, value|
224
- entry = deserialize_entry(value, raw: options[:raw])
223
+ raw_values.each do |key, value|
224
+ entry = deserialize_entry(value, raw: options[:raw])
225
225
 
226
- unless entry.nil? || entry.expired? || entry.mismatched?(normalize_version(keys_to_names[key], options))
227
- begin
228
- values[keys_to_names[key]] = entry.value
229
- rescue DeserializationError
226
+ unless entry.nil? || entry.expired? || entry.mismatched?(normalize_version(keys_to_names[key], options))
227
+ begin
228
+ values[keys_to_names[key]] = entry.value
229
+ rescue DeserializationError
230
+ end
230
231
  end
231
232
  end
232
- end
233
233
 
234
- values
234
+ values
235
+ end
235
236
  end
236
237
 
237
238
  # Delete an entry from the cache.
@@ -150,7 +150,7 @@ module ActiveSupport
150
150
  universal_options = redis_options.extract!(*UNIVERSAL_OPTIONS)
151
151
 
152
152
  if pool_options = self.class.send(:retrieve_pool_options, redis_options)
153
- @redis = ::ConnectionPool.new(pool_options) { self.class.build_redis(**redis_options) }
153
+ @redis = ::ConnectionPool.new(**pool_options) { self.class.build_redis(**redis_options) }
154
154
  else
155
155
  @redis = self.class.build_redis(**redis_options)
156
156
  end
@@ -35,6 +35,7 @@ module ActiveSupport
35
35
  :race_condition_ttl,
36
36
  :serializer,
37
37
  :skip_nil,
38
+ :raw,
38
39
  ]
39
40
 
40
41
  # Mapping of canonical option names to aliases that a store will recognize.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "benchmark"
4
+ return if Benchmark.respond_to?(:ms)
4
5
 
5
6
  class << Benchmark
6
7
  def ms(&block) # :nodoc
@@ -96,14 +96,16 @@ class Class
96
96
  namespaced_name = :"__class_attr_#{name}"
97
97
  ::ActiveSupport::ClassAttribute.redefine(self, name, namespaced_name, default)
98
98
 
99
- delegators = [
100
- "def #{name}; #{namespaced_name}; end",
101
- "def #{name}=(value); self.#{namespaced_name} = value; end",
102
- ]
99
+ class_methods << "def #{name}; #{namespaced_name}; end"
100
+ class_methods << "def #{name}=(value); self.#{namespaced_name} = value; end"
103
101
 
104
- class_methods.concat(delegators)
105
102
  if singleton_class?
106
- methods.concat(delegators)
103
+ methods << <<~RUBY if instance_reader
104
+ silence_redefinition_of_method(:#{name})
105
+ def #{name}
106
+ self.singleton_class.#{name}
107
+ end
108
+ RUBY
107
109
  else
108
110
  methods << <<~RUBY if instance_reader
109
111
  silence_redefinition_of_method def #{name}
@@ -11,7 +11,8 @@ class DateTime
11
11
  #
12
12
  # This method is aliased to <tt>to_formatted_s</tt>.
13
13
  #
14
- # === Examples
14
+ # ==== Examples
15
+ #
15
16
  # datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
16
17
  #
17
18
  # datetime.to_fs(:db) # => "2007-12-04 00:00:00"
@@ -23,7 +24,8 @@ class DateTime
23
24
  # datetime.to_fs(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000"
24
25
  # datetime.to_fs(:iso8601) # => "2007-12-04T00:00:00+00:00"
25
26
  #
26
- # == Adding your own datetime formats to to_fs
27
+ # ==== Adding your own datetime formats to +to_fs+
28
+ #
27
29
  # DateTime formats are shared with Time. You can add your own to the
28
30
  # Time::DATE_FORMATS hash. Use the format name as the hash key and
29
31
  # either a strftime string or Proc instance that takes a time or
@@ -209,10 +209,22 @@ module Enumerable
209
209
  # Set.new.sole # => Enumerable::SoleItemExpectedError: no item found
210
210
  # { a: 1, b: 2 }.sole # => Enumerable::SoleItemExpectedError: multiple items found
211
211
  def sole
212
- case count
213
- when 1 then return first # rubocop:disable Style/RedundantReturn
214
- when 0 then raise ActiveSupport::EnumerableCoreExt::SoleItemExpectedError, "no item found"
215
- when 2.. then raise ActiveSupport::EnumerableCoreExt::SoleItemExpectedError, "multiple items found"
212
+ result = nil
213
+ found = false
214
+
215
+ each do |*element|
216
+ if found
217
+ raise SoleItemExpectedError, "multiple items found"
218
+ end
219
+
220
+ result = element.size == 1 ? element[0] : element
221
+ found = true
222
+ end
223
+
224
+ if found
225
+ result
226
+ else
227
+ raise SoleItemExpectedError, "no item found"
216
228
  end
217
229
  end
218
230
  end
@@ -4,7 +4,7 @@
4
4
  require "json"
5
5
  require "bigdecimal"
6
6
  require "ipaddr"
7
- require "uri/generic"
7
+ require "uri"
8
8
  require "pathname"
9
9
  require "active_support/core_ext/big_decimal/conversions" # for #to_s
10
10
  require "active_support/core_ext/hash/except"
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cgi"
3
+ require "cgi/escape"
4
+ require "cgi/util" if RUBY_VERSION < "3.5"
4
5
 
5
6
  class Object
6
7
  # Alias of <tt>to_s</tt>.
@@ -145,14 +145,14 @@ class NilClass
145
145
  #
146
146
  # With +try+
147
147
  # @person.try(:children).try(:first).try(:name)
148
- def try(*)
148
+ def try(*, &)
149
149
  nil
150
150
  end
151
151
 
152
152
  # Calling +try!+ on +nil+ always returns +nil+.
153
153
  #
154
154
  # nil.try!(:name) # => nil
155
- def try!(*)
155
+ def try!(*, &)
156
156
  nil
157
157
  end
158
158
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Range
4
- # Compare two ranges and see if they overlap each other
5
- # (1..5).overlap?(4..6) # => true
6
- # (1..5).overlap?(7..9) # => false
7
4
  unless Range.method_defined?(:overlap?) # Ruby 3.3+
5
+ # Compare two ranges and see if they overlap each other
6
+ # (1..5).overlap?(4..6) # => true
7
+ # (1..5).overlap?(7..9) # => false
8
8
  def overlap?(other)
9
9
  raise TypeError unless other.is_a? Range
10
10
 
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Range
4
+ # Returns the sole item in the range. If there are no items, or more
5
+ # than one item, raises Enumerable::SoleItemExpectedError.
6
+ #
7
+ # (1..1).sole # => 1
8
+ # (2..1).sole # => Enumerable::SoleItemExpectedError: no item found
9
+ # (..1).sole # => Enumerable::SoleItemExpectedError: infinite range cannot represent a sole item
10
+ def sole
11
+ if self.begin.nil? || self.end.nil?
12
+ raise ActiveSupport::EnumerableCoreExt::SoleItemExpectedError, "infinite range '#{inspect}' cannot represent a sole item"
13
+ end
14
+
15
+ super
16
+ end
17
+ end
@@ -4,3 +4,4 @@ require "active_support/core_ext/range/conversions"
4
4
  require "active_support/core_ext/range/compare_range"
5
5
  require "active_support/core_ext/range/overlap"
6
6
  require "active_support/core_ext/range/each"
7
+ require "active_support/core_ext/range/sole"
@@ -88,11 +88,11 @@ class String
88
88
  # characters.
89
89
  #
90
90
  # >> "🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪".size
91
- # => 20
91
+ # # => 20
92
92
  # >> "🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪".bytesize
93
- # => 80
93
+ # # => 80
94
94
  # >> "🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪".truncate_bytes(20)
95
- # => "🔪🔪🔪🔪…"
95
+ # # => "🔪🔪🔪🔪…"
96
96
  #
97
97
  # The truncated text ends with the <tt>:omission</tt> string, defaulting
98
98
  # to "…", for a total length not exceeding <tt>truncate_to</tt>.
@@ -248,7 +248,7 @@ class String
248
248
  # optional parameter +capitalize+ to false.
249
249
  # By default, this parameter is true.
250
250
  #
251
- # The trailing '_id' can be kept and capitalized by setting the
251
+ # The trailing '_id' can be kept by setting the
252
252
  # optional parameter +keep_id_suffix+ to true.
253
253
  # By default, this parameter is false.
254
254
  #
@@ -12,12 +12,12 @@ class String
12
12
  # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsulated string.
13
13
  #
14
14
  # >> "lj".mb_chars.upcase.to_s
15
- # => "LJ"
15
+ # # => "LJ"
16
16
  #
17
17
  # NOTE: Ruby 2.4 and later support native Unicode case mappings:
18
18
  #
19
19
  # >> "lj".upcase
20
- # => "LJ"
20
+ # # => "LJ"
21
21
  #
22
22
  # == \Method chaining
23
23
  #
@@ -128,7 +128,9 @@ module ActiveSupport # :nodoc:
128
128
  escaped_args = Array(args).map { |arg| explicit_html_escape_interpolated_argument(arg) }
129
129
  end
130
130
 
131
- self.class.new(super(escaped_args))
131
+ new_safe_buffer = self.class.new(super(escaped_args))
132
+ new_safe_buffer.instance_variable_set(:@html_safe, @html_safe)
133
+ new_safe_buffer
132
134
  end
133
135
 
134
136
  attr_reader :html_safe