Skip to content

Commit ea3d8fa

Browse files
authored
Merge pull request #328 from rubyworks/claude/github-connector-capabilities-4qcre6
Fix the failing qed demos
2 parents 5f72f8b + e57f7bf commit ea3d8fa

9 files changed

Lines changed: 55 additions & 24 deletions

File tree

‎HISTORY.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ Changes:
3333
* `Module#alias_module_function` now aliases the singleton method directly.
3434
On JRuby, the singleton method `module_function` created turned private
3535
when aliased again, which broke `URI.hash_to_query` under the test suite.
36+
* `Dir.recurse` and `Dir.ls_r` once again return an Array that leaves out
37+
the starting directory. Deprecating them in favor of `Dir.find` had
38+
quietly changed both.
39+
* `Enumerable::Argumentable#min` and `#max` now pass their arguments to
40+
`#each`, as documented, rather than to Ruby's own `min(n)`/`max(n)`.
41+
42+
* Internal
43+
44+
* Fix the qed demos, which had 8 failures and 2 errors. Most were stale
45+
expectations (`Array#from`, `#step`, `#arrange`, `String#similarity`)
46+
and the date demo held pasted irb output.
3647

3748
## 3.2.2 / 2026-06-15
3849

‎demo/core/array/arrange.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ be of the same class.
1313
[10..15, 16..20, 21, 22].arrange.assert == [10..22]
1414

1515
a = %w{a b c g h i j k m o}
16-
a.arrange.assert == ['a'..'c','g'..'k', 'm' , 'o']
16+
a.arrange.assert == ['a'..'c','g'..'k', 'm'..'m', 'o'..'o']
1717

‎demo/core/array/from.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Returns elements from index i until the end.
66

77
%w{W o r l d}.from(3).assert == %w{l d}
88

9-
Returns entire array for i > length
9+
Returns an empty array for i > length
1010

11-
%w{W o r l d}.from(7).assert == nil
11+
%w{W o r l d}.from(7).assert == []

‎demo/core/array/step.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Enumerator.
77

88
r = []
99
[:a, :b, :c, :d].step(2) { |x| r << x }
10-
r.assert == [:b, :d]
10+
r.assert == [:a, :c]
1111

1212
[:a, :b, :c, :d].step(1).to_a.assert == [:a, :b, :c, :d]
13-
[:a, :b, :c, :d].step(2).to_a.assert == [:b, :d]
14-
[:a, :b, :c, :d].step(3).to_a.assert == [:c]
15-
[:a, :b, :c, :d].step(4).to_a.assert == [:d]
16-
[:a, :b, :c, :d].step(5).to_a.assert == []
13+
[:a, :b, :c, :d].step(2).to_a.assert == [:a, :c]
14+
[:a, :b, :c, :d].step(3).to_a.assert == [:a, :d]
15+
[:a, :b, :c, :d].step(4).to_a.assert == [:a]
16+
[:a, :b, :c, :d].step(5).to_a.assert == [:a]

‎demo/core/string/similarity.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
A fuzzy matching mechanism. Returns a score from 0-1, based on the number of
66
shared edges. To be effective, the strings must be of length 2 or greater.
77

8-
"Alexsander".similarity("Aleksander").assert == 0.9
8+
"Alexsander".similarity("Aleksander").round(2).assert == 0.82
99

1010
"Alexander".similarity("Alexander").assert == 1.0
1111

‎demo/standard/date/comparison.md‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ Allows Times, Dates and DateTimes to be compared with each other. This is useful
66
if you've got an array of Date, DateTime and Time instances and want to sort
77
them correctly (see Loading YAML below for an example of where this can happen).
88

9-
[Time.now - 10, Date.today, DateTime.now + 10].sort
10-
=> [#<Date: 2016-10-08 ((2457670j,0s,0n),+0s,2299161j)>,
11-
2016-10-08 17:29:25 +1300,
12-
#<DateTime: 2016-10-18T17:29:35+13:00 ((2457680j,16175s,182784000n),+46800s,2299161j)>]
9+
list = [Time.utc(2016,10,8,12), Date.new(2016,10,8), DateTime.new(2016,10,18)]
10+
list.sort.map(&:class).assert == [Date, Time, DateTime]
1311

1412
Otherwise, you'll get ArgumentError.
1513

@@ -22,12 +20,11 @@ library which assumes no timezone offset for a given date.
2220
When loading YAML, it's possible that you get back instances of Date and Time
2321
depending on the text format.
2422

25-
YAML::load("#{Date.today.to_s}").class
26-
=> Date
27-
YAML::load("#{DateTime.now.to_s}").class
28-
=> Time
29-
YAML::load("#{Time.now.to_s}").class
30-
=> Time
23+
require 'yaml'
24+
25+
YAML.unsafe_load("2016-10-08").class.assert == Date
26+
YAML.unsafe_load("2016-10-18T17:29:35+13:00").class.assert == Time
27+
YAML.unsafe_load("2016-10-08 17:29:25 +1300").class.assert == Time
3128

3229
It's nice to have some way to sort these entries correctly without having to
3330
impose limits on the format of the YAML document.

‎lib/core/facets/dir/recurse.rb‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@
22

33
class Dir
44

5+
# Recursively list every entry below +path+ (not +path+ itself),
6+
# yielding each one to the block if given.
7+
#
58
# @deprecated Use Dir.find or Find.find instead.
69
def self.recurse(path='.', &block)
710
warn "Dir.recurse is deprecated. Use Dir.find or Find.find instead.", uplevel: 1
8-
Dir.find(path, &block)
11+
recurse_entries(path, &block)
912
end
1013

1114
# @deprecated Use Dir.find or Find.find instead.
1215
def self.ls_r(path='.', &block)
1316
warn "Dir.ls_r is deprecated. Use Dir.find or Find.find instead.", uplevel: 1
14-
Dir.find(path, &block)
17+
recurse_entries(path, &block)
1518
end
1619

20+
# Dir.find yields +path+ first; the old #recurse did not include it.
21+
def self.recurse_entries(path, &block)
22+
list = Dir.find(path).drop(1)
23+
list.each(&block) if block
24+
list
25+
end
26+
private_class_method :recurse_entries
27+
1728
end

‎lib/core/facets/string/similarity.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class String
44
# on the number of shared edges. To be effective, the strings
55
# must be of length 2 or greater.
66
#
7-
# "Alexsander".similarity("Aleksander") #=> 0.9
7+
# "Alexsander".similarity("Aleksander") #=> 0.8181818181818182
88
#
99
# The way it works:
1010
#

‎lib/standard/facets/enumargs.rb‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def #{m}( *args, &yld )
5454
# this branch is used when the method has a variable number of arguments
5555
# resulting in an arity of -1. Right now this is bugged as it does
5656
# not pass the argument to the each, and always passes the argument
57-
# to the method. This makes methods like .min amdn .max to act
58-
# in an unexpected manner.
57+
# to the method. #min and #max are defined explicitly below for
58+
# this reason.
5959
class_eval %{
6060
def #{m}( *args, &yld )
6161
enum_for(:each).#{m}( *args, &yld )
@@ -76,6 +76,18 @@ def to_a(*args)
7676
enum_for(:each, *args).to_a
7777
end
7878

79+
# Support for #min and #max. Ruby's own versions take an optional
80+
# count, so the generic wrapper would pass the argument to them
81+
# instead of to #each.
82+
#
83+
def min(*args, &yld)
84+
enum_for(:each, *args).min(&yld)
85+
end
86+
87+
def max(*args, &yld)
88+
enum_for(:each, *args).max(&yld)
89+
end
90+
7991
# Make exception for #find (a negative arity method) to accept
8092
# keyword argument.
8193
#

0 commit comments

Comments
 (0)