Skip to content

Commit 468acc4

Browse files
transclaude
andcommitted
Review Proc methods; fix dead requires
- Deprecate Proc#compose and Proc#* (use Proc#<< for composition, Ruby 2.6+) - Update Proc#update comment noting Observable is now a gem - Fix dead requires for removed kernel/singleton_class in Proc and Kernel - Remove dead requires for kernel/p and kernel/__dir__ from kernel.rb Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5cfb438 commit 468acc4

6 files changed

Lines changed: 18 additions & 35 deletions

File tree

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Changes:
8989
* Redefine `Comparable#bound` as alias for `clamp`.
9090
* Add `Dir.find` as convenience wrapper around Ruby's `Find.find`.
9191
* Deprecate `Dir.recurse` / `Dir.ls_r` (use `Dir.find` or `Find.find` instead).
92+
* Deprecate `Proc#compose` and `Proc#*` (use `Proc#<<` for right-to-left composition, Ruby 2.6+).
93+
* Fix dead requires for removed `kernel/singleton_class` in Proc and Kernel.
9294
* Remove misplaced `applique/file_helpers` from core (test infrastructure).
9395
* Drop unused `test_files` directive from gemspec. (PR#301)
9496

lib/core/facets/kernel.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
require_relative 'kernel/object_class.rb'
4848
require_relative 'kernel/object_hexid.rb'
4949
require_relative 'kernel/object_send.rb'
50-
require_relative 'kernel/p.rb'
5150
require_relative 'kernel/presence.rb'
5251
require_relative 'kernel/present.rb'
5352
require_relative 'kernel/qua_class.rb'
@@ -56,7 +55,6 @@
5655
require_relative 'kernel/returning.rb'
5756
require_relative 'kernel/silence.rb'
5857
require_relative 'kernel/silence_warnings.rb'
59-
require_relative 'kernel/singleton_class.rb'
6058
require_relative 'kernel/super_method.rb'
6159
require_relative 'kernel/tap.rb'
6260
require_relative 'kernel/temporarily.rb'
@@ -69,7 +67,7 @@
6967
#require_relative 'kernel/y.rb' # uncommon
7068
require_relative 'kernel/yes.rb'
7169
require_relative 'kernel/__class__.rb'
72-
require_relative 'kernel/__dir__.rb'
70+
#require_relative 'kernel/__dir__.rb' # removed, use Ruby's built-in __dir__
7371
require_relative 'kernel/__get__.rb'
7472
require_relative 'kernel/__set__.rb'
7573

lib/core/facets/proc/bind.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'facets/kernel/singleton_class'
2-
31
class Proc
42

53
# Bind a Proc to an object returning a Method.

lib/core/facets/proc/compose.rb

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
11
class Proc
22

3-
# Returns a new proc that is the functional
4-
# composition of two procs, in order.
5-
#
6-
# a = lambda { |x| x + 4 }
7-
# b = lambda { |y| y / 2 }
8-
#
9-
# a.compose(b).call(4) #=> 6
10-
# b.compose(a).call(4) #=> 4
11-
#
12-
# CREDIT: Dave
13-
3+
# @deprecated Use Proc#>> or Proc#<< instead (built-in since Ruby 2.6).
144
def compose(g)
15-
raise ArgumentError, "arity count mismatch" unless arity == g.arity
16-
lambda{ |*a| self[ *g[*a] ] }
5+
warn "Proc#compose is deprecated. Use Proc#<< instead (right-to-left composition).", uplevel: 1
6+
self << g
177
end
188

19-
# Operator for Proc#compose and Integer#times_collect/of.
20-
#
21-
# a = lambda { |x| x + 4 }
22-
# b = lambda { |y| y / 2 }
23-
#
24-
# (a * b).call(4) #=> 6
25-
# (b * a).call(4) #=> 4
26-
#
27-
# CREDIT: Dave
28-
9+
# @deprecated Use Proc#>> or Proc#<< for composition (built-in since Ruby 2.6).
2910
def *(x)
30-
if Integer===x
31-
# collect times
11+
warn "Proc#* is deprecated. Use Proc#<< for composition (right-to-left).", uplevel: 1
12+
if Integer === x
3213
c = []
3314
x.times{|i| c << call(i)}
3415
c
3516
else
36-
# compose procs
37-
lambda{|*a| self[x[*a]]}
17+
self << x
3818
end
3919
end
4020

4121
end
42-

lib/core/facets/proc/to_method.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'facets/proc/bind'
2-
require 'facets/kernel/singleton_class'
32

43
class Proc
54

lib/core/facets/proc/update.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
class Proc
22

3-
# Use a Proc as an observable.
3+
# Alias for #call, allowing a Proc to be used as an Observer.
4+
#
5+
# Ruby's Observable module (now the `observer` gem, removed from
6+
# stdlib in Ruby 3.2) calls #update on observers. This alias
7+
# lets a Proc serve as an observer directly.
8+
#
9+
# TODO: Consider submitting a PR to the observer gem to include
10+
# this extension there instead.
411
#
512
# CREDIT: Tim Pease
613

0 commit comments

Comments
 (0)