Skip to content

Commit 4f264cb

Browse files
committed
Stop loading Kernel#with by default
A global Kernel#with breaks other libraries' methods of that name, such as RSpec's receive(...).with (#290) and Rails 7.1's Object#with. It was already deprecated; now `require 'facets'` no longer loads it either. Following the existing convention for uncommon methods, it stays in lib/core, is commented out of facets/kernel.rb, and is tagged @Uncommon. `require 'facets/kernel/with'` still provides it until its removal after 2027-09-30. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW
1 parent 292a9a8 commit 4f264cb

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎HISTORY.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Changes:
1313
marks the more dangerous method, and quietly ignoring a missing method is
1414
the dangerous behavior. The docs no longer claim ActiveSupport
1515
compatibility.
16+
* `require 'facets'` no longer loads `Kernel#with`, since a global `with`
17+
breaks other libraries' methods of that name, such as RSpec's
18+
`receive(...).with` (#290). It is still available, deprecated, with
19+
`require 'facets/kernel/with'`.
1620
* `Kernel#try` no longer calls private methods. It now behaves exactly like
1721
a normal call or `&.`, raising `NoMethodError` for them.
1822

‎lib/core/facets/kernel.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
require_relative 'kernel/true.rb'
6464
require_relative 'kernel/try.rb'
6565
require_relative 'kernel/val.rb'
66-
require_relative 'kernel/with.rb'
66+
#require_relative 'kernel/with.rb' # uncommon
6767
require_relative 'kernel/writers.rb'
6868
#require_relative 'kernel/y.rb' # uncommon
6969
require_relative 'kernel/yes.rb'

‎lib/core/facets/kernel/with.rb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ module Kernel
1414
# unrelated Object#with that temporarily sets attributes, and this one
1515
# silently replaces it. Scheduled for removal after 2027-09-30.
1616
#
17+
# @uncommon
18+
# require 'facets/kernel/with'
19+
#
1720
def with(obj=self, &block)
1821
warn "Kernel#with is deprecated. Use obj.instance_eval { ... } instead. " \
1922
"It will be removed after 2027-09-30.", uplevel: 1

0 commit comments

Comments
 (0)