File tree Expand file tree Collapse file tree 5 files changed +48
-59
lines changed
Expand file tree Collapse file tree 5 files changed +48
-59
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,10 @@ Changes:
8585 * Remove ` Object#dup! ` and ` Object#try_dup ` (plain ` dup ` works on all objects since Ruby 2.4).
8686 * Remove ` Exception#set_message ` (broken — did not actually change the message).
8787 * Deprecate ` Exception#error_print ` (use ` Exception#full_message ` , adopted by Ruby in 2.5).
88+ * Deprecate ` Comparable#clip ` (use ` Comparable#clamp ` , adopted by Ruby in 2.4).
89+ * Redefine ` Comparable#bound ` as alias for ` clamp ` .
90+ * Add ` Dir.find ` as convenience wrapper around Ruby's ` Find.find ` .
91+ * Deprecate ` Dir.recurse ` / ` Dir.ls_r ` (use ` Dir.find ` or ` Find.find ` instead).
8892 * Remove misplaced ` applique/file_helpers ` from core (test infrastructure).
8993 * Drop unused ` test_files ` directive from gemspec. (PR #301 )
9094
Original file line number Diff line number Diff line change 1- require 'facets/comparable/clip'
1+ module Comparable
2+
3+ # Alias for Comparable#clamp. Reads more naturally in some contexts.
4+ #
5+ # 4.bound(2, 7) #=> 4
6+ # 9.bound(2, 7) #=> 7
7+ # 1.bound(2, 7) #=> 2
8+ #
9+ def bound ( lower , upper = nil )
10+ upper ? clamp ( lower , upper ) : clamp ( lower ..)
11+ end
12+
13+ end
Original file line number Diff line number Diff line change 11module Comparable
22
3- # Returns self if above the given lower bound, or
4- # within the given lower and upper bounds,
5- # otherwise returns the the bound of which the
6- # value falls outside.
7- #
8- # 4.clip(3) #=> 4
9- # 4.clip(5) #=> 5
10- # 4.clip(2,7) #=> 4
11- # 9.clip(2,7) #=> 7
12- # 1.clip(2,7) #=> 2
13- #
14- # CREDIT Florian Gross, Trans
15-
3+ # @deprecated Use Comparable#clamp instead (built-in since Ruby 2.4).
164 def clip ( lower , upper = nil )
17- return lower if self < lower
18- return self unless upper
19- return upper if self > upper
20- return self
5+ warn "Comparable#clip is deprecated. Use Comparable#clamp instead." , uplevel : 1
6+ upper ? clamp ( lower , upper ) : clamp ( lower ..)
217 end
228
23- # Returns self if above the given lower bound, or
24- # within the given lower and upper bounds,
25- # otherwise returns the the bound of which the
26- # value falls outside.
27- #
28- # 4.bound(3) #=> 4
29- # 4.bound(5) #=> 5
30- # 4.bound(2,7) #=> 4
31- # 9.bound(2,7) #=> 7
32- # 1.bound(2,7) #=> 2
33- #
34- # CREDIT: Florian Gross
35-
36- alias_method :bound , :clip
37-
389end
Original file line number Diff line number Diff line change 1+ require 'find'
2+
3+ class Dir
4+
5+ # Recursively traverse a directory, yielding each file and directory path.
6+ # Supports Find.prune to skip subtrees.
7+ #
8+ # Dir.find('.') do |path|
9+ # puts path
10+ # end
11+ #
12+ # Returns an enumerator if no block is given.
13+ #
14+ # This is a convenience wrapper around Ruby's Find.find.
15+
16+ def self . find ( *paths , ignore_error : true , &block )
17+ Find . find ( *paths , ignore_error : ignore_error , &block )
18+ end
19+
20+ end
Original file line number Diff line number Diff line change 1+ require 'facets/dir/find'
2+
13class Dir
24
3- # Recursively scan a directory and pass each file to the given block.
4- #
5- # Dir.recurse('.') do |path|
6- # # ...
7- # end
8- #
9- # CREDIT: George Moschovitis
10- #
11- # TODO: If fully compatible, reimplement as alias of Find.find,
12- # or just copy and paste Find.find code here if it looks more robust.
13- #
5+ # @deprecated Use Dir.find or Find.find instead.
146 def self . recurse ( path = '.' , &block )
15- list = [ ]
16- stoplist = [ '.' , '..' ]
17- Dir . foreach ( path ) do |f |
18- next if stoplist . include? ( f )
19- filename = ( path == '.' ? f : path + '/' + f )
20- list << filename
21- block . call ( filename ) if block
22- if FileTest . directory? ( filename ) and not FileTest . symlink? ( filename )
23- list . concat ( Dir . recurse ( filename , &block ) )
24- end
25- end
26- list
7+ warn "Dir.recurse is deprecated. Use Dir.find or Find.find instead." , uplevel : 1
8+ Dir . find ( path , &block )
279 end
2810
29- # Same as Dir#recurse .
11+ # @deprecated Use Dir.find or Find.find instead .
3012 def self . ls_r ( path = '.' , &block )
31- recurse ( path , &block )
13+ warn "Dir.ls_r is deprecated. Use Dir.find or Find.find instead." , uplevel : 1
14+ Dir . find ( path , &block )
3215 end
3316
3417end
35-
You can’t perform that action at this time.
0 commit comments