facets 3.2.2 → 4.0.1
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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +50 -15
- data/HISTORY.md +164 -0
- data/LICENSE.txt +1 -1
- data/README.md +54 -217
- data/lib/core/facets/array/nonuniq.rb +2 -2
- data/lib/core/facets/array/standard_deviation.rb +1 -1
- data/lib/core/facets/array/uniq_by.rb +5 -1
- data/lib/core/facets/array.rb +5 -1
- data/lib/core/facets/binding/self.rb +2 -1
- data/lib/core/facets/comparable/clip.rb +2 -1
- data/lib/core/facets/dir/recurse.rb +17 -4
- data/lib/core/facets/enumerable/compact_map.rb +1 -1
- data/lib/core/facets/enumerable/defer.rb +1 -1
- data/lib/core/facets/enumerable/frequency.rb +1 -1
- data/lib/core/facets/enumerable/graph.rb +1 -1
- data/lib/core/facets/enumerable/hashify.rb +2 -2
- data/lib/core/facets/enumerable/hinge.rb +1 -1
- data/lib/core/facets/enumerable/map_by.rb +6 -2
- data/lib/core/facets/enumerable/map_with_index.rb +1 -1
- data/lib/core/facets/enumerable/mash.rb +2 -1
- data/lib/core/facets/enumerable/uniq_by.rb +3 -1
- data/lib/core/facets/essentials.rb +4 -1
- data/lib/core/facets/exception/error_print.rb +4 -2
- data/lib/core/facets/file/null.rb +2 -1
- data/lib/core/facets/file/read_binary.rb +2 -1
- data/lib/core/facets/file.rb +1 -1
- data/lib/core/facets/hash/fetch_nested.rb +2 -1
- data/lib/core/facets/hash/update_keys.rb +2 -1
- data/lib/core/facets/hash/update_values.rb +2 -1
- data/lib/core/facets/hash.rb +6 -4
- data/lib/core/facets/kernel/deep_clone.rb +36 -8
- data/lib/core/facets/kernel/eigenclass.rb +2 -1
- data/lib/core/facets/kernel/extension.rb +2 -1
- data/lib/core/facets/kernel/instance_class.rb +2 -1
- data/lib/core/facets/kernel/instance_send.rb +2 -1
- data/lib/core/facets/kernel/like.rb +7 -2
- data/lib/core/facets/kernel/load_relative.rb +2 -1
- data/lib/core/facets/kernel/memo.rb +2 -1
- data/lib/core/facets/kernel/meta.rb +1 -1
- data/lib/core/facets/kernel/object_class.rb +2 -1
- data/lib/core/facets/kernel/object_send.rb +2 -1
- data/lib/core/facets/kernel/qua_class.rb +2 -1
- data/lib/core/facets/kernel/returning.rb +3 -1
- data/lib/core/facets/kernel/silence.rb +38 -30
- data/lib/core/facets/kernel/tee.rb +3 -0
- data/lib/core/facets/kernel/try.rb +25 -14
- data/lib/core/facets/kernel/with.rb +15 -9
- data/lib/core/facets/kernel.rb +1 -1
- data/lib/core/facets/module/alias_class_method.rb +8 -3
- data/lib/core/facets/module/alias_method_chain.rb +3 -1
- data/lib/core/facets/module/alias_module_function.rb +4 -1
- data/lib/core/facets/module/can.rb +2 -1
- data/lib/core/facets/module/module_def.rb +0 -11
- data/lib/core/facets/module/redefine_method.rb +12 -3
- data/lib/core/facets/objectspace/op_fetch.rb +2 -1
- data/lib/core/facets/proc/compose.rb +4 -2
- data/lib/core/facets/rails_bridge.rb +27 -0
- data/lib/core/facets/string/camelcase.rb +6 -0
- data/lib/core/facets/string/similarity.rb +3 -2
- data/lib/core/facets/struct/attributes.rb +1 -1
- data/lib/core/facets/time/round_to.rb +1 -1
- data/lib/core/facets/time/to_time.rb +7 -2
- data/lib/core/facets/time/trunc.rb +2 -1
- data/lib/core/facets/unboundmethod/arguments.rb +1 -1
- data/lib/core/facets/version.rb +1 -1
- data/lib/rails/facets/hash/to_options.rb +14 -0
- data/lib/{core → rails}/facets/module/mattr.rb +30 -30
- data/lib/standard/facets/cloneable.rb +5 -3
- data/lib/standard/facets/continuation.rb +2 -1
- data/lib/standard/facets/enumargs.rb +14 -2
- data/lib/standard/facets/find/select.rb +3 -1
- data/lib/standard/facets/getoptlong.rb +2 -1
- data/lib/standard/facets/interval.rb +5 -4
- data/lib/standard/facets/load_monitor.rb +2 -1
- data/lib/standard/facets/math/percentile.rb +9 -4
- data/lib/standard/facets/pathname/null.rb +2 -1
- data/lib/standard/facets/random.rb +8 -4
- data/lib/standard/facets/shellwords.rb +6 -10
- metadata +14 -12
- data/lib/core/facets/hash/to_options.rb +0 -1
- /data/lib/{core → rails}/facets/array/extract_options.rb +0 -0
- /data/lib/{core → rails}/facets/cattr.rb +0 -0
- /data/lib/{core → rails}/facets/class/cattr.rb +0 -0
- /data/lib/{standard → rails}/facets/date.rb +0 -0
- /data/lib/{core → rails}/facets/file/atomic_write.rb +0 -0
- /data/lib/{core → rails}/facets/hash/slice.rb +0 -0
- /data/lib/{core → rails}/facets/hash/stringify_keys.rb +0 -0
- /data/lib/{core → rails}/facets/hash/symbolize_keys.rb +0 -0
- /data/lib/{core → rails}/facets/module/cattr.rb +0 -0
|
@@ -3,21 +3,26 @@ require 'facets/functor'
|
|
|
3
3
|
module Kernel
|
|
4
4
|
|
|
5
5
|
# Invokes the method identified by the symbol +method+, passing it any
|
|
6
|
-
# arguments and/or the block specified.
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
# Compatible with ActiveSupport's #try, plus an additional Functor
|
|
12
|
-
# form when called with no arguments and no block.
|
|
6
|
+
# arguments and/or the block specified. If the receiver is +nil+, it
|
|
7
|
+
# returns +nil+ instead (see NilClass#try below). Otherwise it behaves
|
|
8
|
+
# exactly like a normal call (or &.): a method the receiver doesn't have,
|
|
9
|
+
# or a private one, raises NoMethodError.
|
|
13
10
|
#
|
|
14
11
|
# @example.try(:name) #=> "bob"
|
|
15
|
-
# @example.try { |o| o.name } #=> "bob"
|
|
16
|
-
# @example.try.name #=> "bob" (
|
|
12
|
+
# @example.try { |o| o.name } #=> "bob"
|
|
13
|
+
# @example.try.name #=> "bob" (Functor form)
|
|
14
|
+
# nil.try.name #=> nil
|
|
15
|
+
#
|
|
16
|
+
# NOTE: THIS IS NOT ACTIVESUPPORT'S #try. SINCE RAILS 4.0, ACTIVESUPPORT'S
|
|
17
|
+
# #try RETURNS NIL FOR A METHOD THE RECEIVER DOESN'T HAVE, SO A TYPO LIKE
|
|
18
|
+
# user.try(:nmae) QUIETLY BECOMES NIL AND HIDES THE BUG. FACETS KEEPS #try
|
|
19
|
+
# STRICT AND PUTS THE LENIENT BEHAVIOR IN #try!, WHERE IT BELONGS: IN RUBY,
|
|
20
|
+
# THE BANG MARKS THE MORE DANGEROUS VERSION OF A METHOD, AND SWALLOWING A
|
|
21
|
+
# MISSING METHOD IS THE DANGEROUS ONE. RAILS HAS THE TWO BACKWARD.
|
|
17
22
|
#
|
|
18
23
|
def try(method=nil, *args, &block)
|
|
19
24
|
if method
|
|
20
|
-
|
|
25
|
+
public_send(method, *args, &block)
|
|
21
26
|
elsif block_given?
|
|
22
27
|
yield self
|
|
23
28
|
else
|
|
@@ -25,12 +30,19 @@ module Kernel
|
|
|
25
30
|
end
|
|
26
31
|
end
|
|
27
32
|
|
|
28
|
-
# Like #try, but
|
|
29
|
-
# (
|
|
33
|
+
# Like #try, but also returns +nil+ if the receiver doesn't respond to
|
|
34
|
+
# +method+ (or it is private), instead of raising NoMethodError.
|
|
35
|
+
#
|
|
36
|
+
# @example.try!(:name) #=> "bob"
|
|
37
|
+
# @example.try!(:nmae) #=> nil
|
|
38
|
+
#
|
|
39
|
+
# NOTE: THIS IS THE OPPOSITE OF ACTIVESUPPORT'S #try!, WHICH RAISES. THE
|
|
40
|
+
# BANG IS HERE BECAUSE QUIETLY IGNORING A MISSING METHOD IS THE DANGEROUS
|
|
41
|
+
# BEHAVIOR; SEE #try ABOVE.
|
|
30
42
|
#
|
|
31
43
|
def try!(method=nil, *args, &block)
|
|
32
44
|
if method
|
|
33
|
-
public_send(method, *args, &block)
|
|
45
|
+
public_send(method, *args, &block) if respond_to?(method)
|
|
34
46
|
elsif block_given?
|
|
35
47
|
yield self
|
|
36
48
|
else
|
|
@@ -40,7 +52,6 @@ module Kernel
|
|
|
40
52
|
|
|
41
53
|
end
|
|
42
54
|
|
|
43
|
-
|
|
44
55
|
class NilClass
|
|
45
56
|
|
|
46
57
|
# See Kernel#try.
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
module Kernel
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
#
|
|
3
|
+
# Evaluate the block with +obj+ as self and return the block's value.
|
|
4
|
+
# It is simply a more readable spelling of #instance_eval.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# end
|
|
6
|
+
# values = []
|
|
7
|
+
# with values do
|
|
8
|
+
# self << 'bar'
|
|
9
|
+
# self << 'baz'
|
|
11
10
|
# end
|
|
11
|
+
# values # => ['bar', 'baz']
|
|
12
12
|
#
|
|
13
|
-
#
|
|
13
|
+
# @deprecated Use obj.instance_eval { ... } instead. Rails 7.1 defines an
|
|
14
|
+
# unrelated Object#with that temporarily sets attributes, and this one
|
|
15
|
+
# silently replaces it. Scheduled for removal after 2027-09-30.
|
|
16
|
+
#
|
|
17
|
+
# @uncommon
|
|
18
|
+
# require 'facets/kernel/with'
|
|
14
19
|
#
|
|
15
20
|
def with(obj=self, &block)
|
|
21
|
+
warn "Kernel#with is deprecated. Use obj.instance_eval { ... } instead. " \
|
|
22
|
+
"It will be removed after 2027-09-30.", uplevel: 1
|
|
16
23
|
obj.instance_eval(&block)
|
|
17
24
|
end
|
|
18
25
|
|
|
19
26
|
end
|
|
20
|
-
|
data/lib/core/facets/kernel.rb
CHANGED
|
@@ -63,7 +63,7 @@ require_relative 'kernel/temporarily.rb'
|
|
|
63
63
|
require_relative 'kernel/true.rb'
|
|
64
64
|
require_relative 'kernel/try.rb'
|
|
65
65
|
require_relative 'kernel/val.rb'
|
|
66
|
-
require_relative 'kernel/with.rb'
|
|
66
|
+
#require_relative 'kernel/with.rb' # uncommon
|
|
67
67
|
require_relative 'kernel/writers.rb'
|
|
68
68
|
#require_relative 'kernel/y.rb' # uncommon
|
|
69
69
|
require_relative 'kernel/yes.rb'
|
|
@@ -2,10 +2,15 @@ class Module
|
|
|
2
2
|
|
|
3
3
|
# Alias a class method.
|
|
4
4
|
#
|
|
5
|
+
# class Greeter
|
|
6
|
+
# def self.hello; "Hello"; end
|
|
7
|
+
# alias_class_method :hi, :hello
|
|
8
|
+
# end
|
|
9
|
+
#
|
|
10
|
+
# Greeter.hi #=> "Hello"
|
|
11
|
+
#
|
|
5
12
|
def alias_class_method(name, target)
|
|
6
|
-
|
|
7
|
-
alias_method(name, target)
|
|
8
|
-
end
|
|
13
|
+
singleton_class.alias_method(name, target)
|
|
9
14
|
end
|
|
10
15
|
|
|
11
16
|
end
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
class Module
|
|
2
2
|
|
|
3
3
|
# @deprecated Use Module#prepend instead (built-in since Ruby 2.0).
|
|
4
|
+
# Scheduled for removal after 2027-09-30.
|
|
4
5
|
#
|
|
5
6
|
# The alias_method_chain pattern has been superseded by Module#prepend,
|
|
6
7
|
# which provides a cleaner way to wrap methods.
|
|
7
8
|
#
|
|
8
9
|
def alias_method_chain(target, feature)
|
|
9
|
-
warn "Module#alias_method_chain is deprecated. Use Module#prepend instead."
|
|
10
|
+
warn "Module#alias_method_chain is deprecated. Use Module#prepend instead. " \
|
|
11
|
+
"It will be removed after 2027-09-30.", uplevel: 1
|
|
10
12
|
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
|
11
13
|
yield(aliased_target, punctuation) if block_given?
|
|
12
14
|
|
|
@@ -23,7 +23,10 @@ class Module
|
|
|
23
23
|
#
|
|
24
24
|
def alias_module_function(new, old)
|
|
25
25
|
alias_method(new, old)
|
|
26
|
-
module_function(new)
|
|
26
|
+
return module_function(new) unless singleton_class.method_defined?(old)
|
|
27
|
+
# Alias the singleton method directly. On JRuby, a singleton method made
|
|
28
|
+
# by #module_function turns private when it is itself aliased later.
|
|
29
|
+
singleton_class.send(:alias_method, new, old)
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
end
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
class Module
|
|
2
2
|
|
|
3
3
|
# @deprecated Use Module#extend instead.
|
|
4
|
+
# Scheduled for removal after 2027-09-30.
|
|
4
5
|
def can(*mods)
|
|
5
|
-
warn "Module#can is deprecated. Use Module#extend instead.", uplevel: 1
|
|
6
|
+
warn "Module#can is deprecated. Use Module#extend instead. It will be removed after 2027-09-30.", uplevel: 1
|
|
6
7
|
extend(*mods)
|
|
7
8
|
end
|
|
8
9
|
|
|
@@ -16,16 +16,5 @@ class Module
|
|
|
16
16
|
module_eval { define_method name, &blk }
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
#--
|
|
20
|
-
# TODO: Why are we making these protected,
|
|
21
|
-
# and where should these really go in Facets?
|
|
22
|
-
#++
|
|
23
|
-
protected :attr
|
|
24
|
-
protected :attr_reader
|
|
25
|
-
protected :attr_writer
|
|
26
|
-
protected :attr_accessor
|
|
27
|
-
protected :remove_method
|
|
28
|
-
protected :undef_method
|
|
29
|
-
|
|
30
19
|
end
|
|
31
20
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
class Module
|
|
2
2
|
|
|
3
|
-
private
|
|
4
|
-
|
|
5
3
|
# Creates a new method for a pre-existing method.
|
|
6
4
|
#
|
|
7
5
|
# If _aka_ is given, then the method being redefined will
|
|
@@ -21,14 +19,25 @@ class Module
|
|
|
21
19
|
#
|
|
22
20
|
# Greeter.new.hello #=> "Hello, friend!"
|
|
23
21
|
#
|
|
22
|
+
# The new method keeps the visibility of the one it replaces. Like
|
|
23
|
+
# ActiveSupport's Module#redefine_method, this is public.
|
|
24
|
+
#
|
|
24
25
|
# CREDIT: Trans
|
|
25
26
|
|
|
26
27
|
def redefine_method(sym, aka=nil, &blk)
|
|
28
|
+
visibility = if private_method_defined?(sym)
|
|
29
|
+
:private
|
|
30
|
+
elsif protected_method_defined?(sym)
|
|
31
|
+
:protected
|
|
32
|
+
else
|
|
33
|
+
:public
|
|
34
|
+
end
|
|
27
35
|
alias_method(aka, sym) if aka
|
|
28
36
|
## prevent warning about method overwrite
|
|
29
37
|
begin remove_method(sym) rescue NameError end
|
|
30
|
-
## define
|
|
38
|
+
## define replacement method
|
|
31
39
|
define_method(sym, &blk)
|
|
40
|
+
__send__(visibility, sym)
|
|
32
41
|
end
|
|
33
42
|
|
|
34
43
|
#
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
class Proc
|
|
2
2
|
|
|
3
3
|
# @deprecated Use Proc#>> or Proc#<< instead (built-in since Ruby 2.6).
|
|
4
|
+
# Scheduled for removal after 2027-09-30.
|
|
4
5
|
def compose(g)
|
|
5
|
-
warn "Proc#compose is deprecated. Use Proc#<< instead (right-to-left composition).", uplevel: 1
|
|
6
|
+
warn "Proc#compose is deprecated. Use Proc#<< instead (right-to-left composition). It will be removed after 2027-09-30.", uplevel: 1
|
|
6
7
|
self << g
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
# @deprecated Use Proc#>> or Proc#<< for composition (built-in since Ruby 2.6).
|
|
11
|
+
# Scheduled for removal after 2027-09-30.
|
|
10
12
|
def *(x)
|
|
11
|
-
warn "Proc#* is deprecated. Use Proc#<< for composition (right-to-left).", uplevel: 1
|
|
13
|
+
warn "Proc#* is deprecated. Use Proc#<< for composition (right-to-left). It will be removed after 2027-09-30.", uplevel: 1
|
|
12
14
|
if Integer === x
|
|
13
15
|
c = []
|
|
14
16
|
x.times{|i| c << call(i)}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Facets
|
|
2
|
+
|
|
3
|
+
# Until 2027-09-30, `require 'facets'` still provides a few Rails-compatible
|
|
4
|
+
# methods that now live in lib/rails. Each is defined here as a stub that
|
|
5
|
+
# warns on first use, loads the real file (which replaces the stub), and
|
|
6
|
+
# retries the call. Requiring the file directly skips the stub and the
|
|
7
|
+
# warning. Methods that are already defined, e.g. by ActiveSupport, are
|
|
8
|
+
# left alone.
|
|
9
|
+
#
|
|
10
|
+
# Facets.rails_bridge(Hash, 'facets/hash/slice', :slice!)
|
|
11
|
+
#
|
|
12
|
+
def self.rails_bridge(owner, file, *names)
|
|
13
|
+
names.each do |name|
|
|
14
|
+
next if owner.method_defined?(name)
|
|
15
|
+
owner.send(:define_method, name) do |*args, &block|
|
|
16
|
+
warn "#{owner}##{name} will no longer be loaded by `require 'facets'` after 2027-09-30. " \
|
|
17
|
+
"Add `require '#{file}'` to keep using it.", uplevel: 1
|
|
18
|
+
require file
|
|
19
|
+
if owner.instance_method(name).source_location&.first == __FILE__
|
|
20
|
+
raise NoMethodError, "#{file} did not define #{owner}##{name}"
|
|
21
|
+
end
|
|
22
|
+
__send__(name, *args, &block)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -52,8 +52,11 @@ class String
|
|
|
52
52
|
#
|
|
53
53
|
# @deprecated
|
|
54
54
|
# Use `#camelcase(:upper)` instead.
|
|
55
|
+
# Scheduled for removal after 2027-09-30.
|
|
55
56
|
#
|
|
56
57
|
def upper_camelcase(*separators)
|
|
58
|
+
warn "String#upper_camelcase is deprecated. Use String#camelcase(:upper) instead. " \
|
|
59
|
+
"It will be removed after 2027-09-30.", uplevel: 1
|
|
57
60
|
camelcase(:upper, *separators)
|
|
58
61
|
end
|
|
59
62
|
|
|
@@ -64,8 +67,11 @@ class String
|
|
|
64
67
|
#
|
|
65
68
|
# @deprecated
|
|
66
69
|
# Use `#camelcase(:lower)` instead.
|
|
70
|
+
# Scheduled for removal after 2027-09-30.
|
|
67
71
|
#
|
|
68
72
|
def lower_camelcase(*separators)
|
|
73
|
+
warn "String#lower_camelcase is deprecated. Use String#camelcase(:lower) instead. " \
|
|
74
|
+
"It will be removed after 2027-09-30.", uplevel: 1
|
|
69
75
|
camelcase(:lower, *separators)
|
|
70
76
|
end
|
|
71
77
|
|
|
@@ -82,8 +82,9 @@ class String
|
|
|
82
82
|
|
|
83
83
|
score = 0.0
|
|
84
84
|
matches.each{ |mm| score += mm.length }
|
|
85
|
-
|
|
86
|
-
return
|
|
85
|
+
largest = [self.length, str_in.length].max
|
|
86
|
+
return 0.0 if largest.zero? # e.g. an empty Symbol or Array
|
|
87
|
+
return score/largest
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
end
|
|
@@ -6,7 +6,7 @@ class Struct
|
|
|
6
6
|
# This will eventually be deprecated in favor of #to_h.
|
|
7
7
|
|
|
8
8
|
def attributes
|
|
9
|
-
warn "Struct#attributes is deprecated. Use Struct#to_h instead.", uplevel: 1
|
|
9
|
+
warn "Struct#attributes is deprecated. Use Struct#to_h instead. It will be removed after 2027-09-30.", uplevel: 1
|
|
10
10
|
to_h
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -4,9 +4,14 @@ class Time
|
|
|
4
4
|
|
|
5
5
|
# To be able to keep Dates and Times interchangeable
|
|
6
6
|
# on conversions.
|
|
7
|
-
|
|
7
|
+
#
|
|
8
|
+
# @deprecated Ruby defines Time#to_time once 'date' is loaded.
|
|
9
|
+
# Scheduled for removal after 2027-09-30.
|
|
10
|
+
#
|
|
8
11
|
def to_time
|
|
9
|
-
|
|
12
|
+
warn "Facets' Time#to_time is deprecated. Require 'date' for Ruby's own Time#to_time. " \
|
|
13
|
+
"It will be removed after 2027-09-30.", uplevel: 1
|
|
14
|
+
getlocal
|
|
10
15
|
end
|
|
11
16
|
|
|
12
17
|
# A method to keep Time, Date and DateTime instances interchangeable
|
|
@@ -14,8 +14,9 @@ class Time
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
# @deprecated Use Time#floor_to instead.
|
|
17
|
+
# Scheduled for removal after 2027-09-30.
|
|
17
18
|
def trunc(seconds)
|
|
18
|
-
warn "Time#trunc is deprecated. Use Time#floor_to instead.", uplevel: 1
|
|
19
|
+
warn "Time#trunc is deprecated. Use Time#floor_to instead. It will be removed after 2027-09-30.", uplevel: 1
|
|
19
20
|
floor_to(seconds)
|
|
20
21
|
end
|
|
21
22
|
|
|
@@ -19,7 +19,7 @@ class UnboundMethod
|
|
|
19
19
|
# CREDIT: Trans
|
|
20
20
|
|
|
21
21
|
def arguments
|
|
22
|
-
warn "UnboundMethod#arguments is deprecated. Use UnboundMethod#parameters instead.", uplevel: 1
|
|
22
|
+
warn "UnboundMethod#arguments is deprecated. Use UnboundMethod#parameters instead. It will be removed after 2027-09-30.", uplevel: 1
|
|
23
23
|
ar = arity
|
|
24
24
|
case ar <=> 0
|
|
25
25
|
when 1
|
data/lib/core/facets/version.rb
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'facets/hash/symbolize_keys'
|
|
2
|
+
|
|
3
|
+
class Hash
|
|
4
|
+
|
|
5
|
+
# Rails' name for #symbolize_keys.
|
|
6
|
+
#
|
|
7
|
+
# {'a'=>1}.to_options #=> {:a=>1}
|
|
8
|
+
#
|
|
9
|
+
alias_method :to_options, :symbolize_keys
|
|
10
|
+
|
|
11
|
+
# Rails' name for #symbolize_keys!.
|
|
12
|
+
alias_method :to_options!, :symbolize_keys!
|
|
13
|
+
|
|
14
|
+
end
|
|
@@ -19,13 +19,13 @@ class Module
|
|
|
19
19
|
# @uncommon
|
|
20
20
|
# require 'facets/module/cattr'
|
|
21
21
|
#
|
|
22
|
-
def cattr(*syms)
|
|
22
|
+
def cattr(*syms, &block)
|
|
23
23
|
writers, readers = syms.flatten.partition{ |a| a.to_s =~ /=$/ }
|
|
24
24
|
writers = writers.map{ |e| e.to_s.chomp('=').to_sym }
|
|
25
25
|
##readers.concat( writers ) # writers also get readers
|
|
26
26
|
|
|
27
|
-
cattr_reader(*readers)
|
|
28
|
-
cattr_writer(*writers)
|
|
27
|
+
cattr_reader(*readers, &block)
|
|
28
|
+
cattr_writer(*writers, &block)
|
|
29
29
|
|
|
30
30
|
return readers + writers
|
|
31
31
|
end
|
|
@@ -49,13 +49,13 @@ class Module
|
|
|
49
49
|
# @uncommon
|
|
50
50
|
# require 'facets/module/cattr'
|
|
51
51
|
#
|
|
52
|
-
def cattr_reader(*syms)
|
|
52
|
+
def cattr_reader(*syms, &block)
|
|
53
53
|
syms.flatten.each do |sym|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
end
|
|
54
|
+
unless class_variable_defined?("@@#{sym}")
|
|
55
|
+
class_variable_set("@@#{sym}", block ? block.call : nil)
|
|
56
|
+
end
|
|
58
57
|
|
|
58
|
+
module_eval(<<-EOS, __FILE__, __LINE__)
|
|
59
59
|
def self.#{sym}
|
|
60
60
|
@@#{sym}
|
|
61
61
|
end
|
|
@@ -91,13 +91,13 @@ class Module
|
|
|
91
91
|
# @uncommon
|
|
92
92
|
# require 'facets/module/cattr'
|
|
93
93
|
#
|
|
94
|
-
def cattr_writer(*syms)
|
|
94
|
+
def cattr_writer(*syms, &block)
|
|
95
95
|
syms.flatten.each do |sym|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
end
|
|
96
|
+
unless class_variable_defined?("@@#{sym}")
|
|
97
|
+
class_variable_set("@@#{sym}", block ? block.call : nil)
|
|
98
|
+
end
|
|
100
99
|
|
|
100
|
+
module_eval(<<-EOS, __FILE__, __LINE__)
|
|
101
101
|
def self.#{sym}=(obj)
|
|
102
102
|
@@#{sym} = obj
|
|
103
103
|
end
|
|
@@ -130,8 +130,8 @@ class Module
|
|
|
130
130
|
# @uncommon
|
|
131
131
|
# require 'facets/module/cattr'
|
|
132
132
|
#
|
|
133
|
-
def cattr_accessor(*syms)
|
|
134
|
-
cattr_reader(*syms) + cattr_writer(*syms)
|
|
133
|
+
def cattr_accessor(*syms, &block)
|
|
134
|
+
cattr_reader(*syms, &block) + cattr_writer(*syms)
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
# Creates a class-variable attribute that can
|
|
@@ -159,13 +159,13 @@ class Module
|
|
|
159
159
|
# @uncommon
|
|
160
160
|
# require 'facets/module/mattr'
|
|
161
161
|
#
|
|
162
|
-
def mattr(*syms)
|
|
162
|
+
def mattr(*syms, &block)
|
|
163
163
|
writers, readers = syms.flatten.partition{ |a| a.to_s =~ /=$/ }
|
|
164
164
|
writers = writers.collect{ |e| e.to_s.chomp('=').to_sym }
|
|
165
165
|
##readers.concat( writers ) # writers also get readers
|
|
166
166
|
|
|
167
|
-
mattr_writer( *writers )
|
|
168
|
-
mattr_reader( *readers )
|
|
167
|
+
mattr_writer( *writers, &block )
|
|
168
|
+
mattr_reader( *readers, &block )
|
|
169
169
|
|
|
170
170
|
return readers + writers
|
|
171
171
|
end
|
|
@@ -189,13 +189,13 @@ class Module
|
|
|
189
189
|
# @uncommon
|
|
190
190
|
# require 'facets/module/mattr'
|
|
191
191
|
#
|
|
192
|
-
def mattr_reader( *syms )
|
|
192
|
+
def mattr_reader( *syms, &block )
|
|
193
193
|
syms.flatten.each do |sym|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
end
|
|
194
|
+
unless class_variable_defined?("@@#{sym}")
|
|
195
|
+
class_variable_set("@@#{sym}", block ? block.call : nil)
|
|
196
|
+
end
|
|
198
197
|
|
|
198
|
+
module_eval(<<-EOS, __FILE__, __LINE__)
|
|
199
199
|
def self.#{sym}
|
|
200
200
|
@@#{sym}
|
|
201
201
|
end
|
|
@@ -232,13 +232,13 @@ class Module
|
|
|
232
232
|
# @uncommon
|
|
233
233
|
# require 'facets/module/mattr'
|
|
234
234
|
#
|
|
235
|
-
def mattr_writer(*syms)
|
|
235
|
+
def mattr_writer(*syms, &block)
|
|
236
236
|
syms.flatten.each do |sym|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
end
|
|
237
|
+
unless class_variable_defined?("@@#{sym}")
|
|
238
|
+
class_variable_set("@@#{sym}", block ? block.call : nil)
|
|
239
|
+
end
|
|
241
240
|
|
|
241
|
+
module_eval(<<-EOS, __FILE__, __LINE__)
|
|
242
242
|
def self.#{sym}=(obj)
|
|
243
243
|
@@#{sym} = obj
|
|
244
244
|
end
|
|
@@ -272,8 +272,8 @@ class Module
|
|
|
272
272
|
# @uncommon
|
|
273
273
|
# require 'facets/module/mattr'
|
|
274
274
|
#
|
|
275
|
-
def mattr_accessor(*syms)
|
|
276
|
-
mattr_reader(*syms) + mattr_writer(*syms)
|
|
275
|
+
def mattr_accessor(*syms, &block)
|
|
276
|
+
mattr_reader(*syms, &block) + mattr_writer(*syms)
|
|
277
277
|
end
|
|
278
278
|
|
|
279
279
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
# @deprecated Use
|
|
2
|
-
# initialize_copy method.
|
|
3
|
-
|
|
1
|
+
# @deprecated Use Kernel#deep_clone (`require 'facets/kernel/deep_clone'`)
|
|
2
|
+
# instead, or define your own initialize_copy method.
|
|
3
|
+
# Scheduled for removal after 2027-09-30.
|
|
4
|
+
warn "facets/cloneable is deprecated. Use Kernel#deep_clone (require 'facets/kernel/deep_clone') " \
|
|
5
|
+
"or define your own initialize_copy instead. It will be removed after 2027-09-30.", uplevel: 1
|
|
4
6
|
|
|
5
7
|
module Cloneable
|
|
6
8
|
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
# @deprecated callcc is obsolete in Ruby. Use Fiber instead.
|
|
2
|
-
|
|
2
|
+
# Scheduled for removal after 2027-09-30.
|
|
3
|
+
warn "facets/continuation is deprecated. callcc is obsolete; use Fiber instead. It will be removed after 2027-09-30.", uplevel: 1
|
|
@@ -54,8 +54,8 @@ module Enumerable
|
|
|
54
54
|
# this branch is used when the method has a variable number of arguments
|
|
55
55
|
# resulting in an arity of -1. Right now this is bugged as it does
|
|
56
56
|
# not pass the argument to the each, and always passes the argument
|
|
57
|
-
# to the method.
|
|
58
|
-
#
|
|
57
|
+
# to the method. #min and #max are defined explicitly below for
|
|
58
|
+
# this reason.
|
|
59
59
|
class_eval %{
|
|
60
60
|
def #{m}( *args, &yld )
|
|
61
61
|
enum_for(:each).#{m}( *args, &yld )
|
|
@@ -76,6 +76,18 @@ module Enumerable
|
|
|
76
76
|
enum_for(:each, *args).to_a
|
|
77
77
|
end
|
|
78
78
|
|
|
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
|
+
|
|
79
91
|
# Make exception for #find (a negative arity method) to accept
|
|
80
92
|
# keyword argument.
|
|
81
93
|
#
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'find'
|
|
2
|
+
|
|
1
3
|
module Find
|
|
2
4
|
# Identical to find except select returns the matching files as an array.
|
|
3
5
|
# (find returns nil, which is not very useful if you actually wanted an array.)
|
|
@@ -8,7 +10,7 @@ module Find
|
|
|
8
10
|
#
|
|
9
11
|
# CREDIT: Tyler Rick
|
|
10
12
|
def self.select(*paths, &block)
|
|
11
|
-
|
|
13
|
+
find(*paths).select(&block)
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
# @deprecated GetoptLong is a bundled gem heading for removal.
|
|
2
2
|
# Consider using OptionParser or a modern CLI library instead.
|
|
3
|
-
|
|
3
|
+
# Scheduled for removal after 2027-09-30.
|
|
4
|
+
warn "facets/getoptlong is deprecated. Consider OptionParser instead. It will be removed after 2027-09-30.", uplevel: 1
|
|
@@ -189,11 +189,12 @@ class Interval
|
|
|
189
189
|
# 1..5.each(2) { |e| ... } #=> 1 3 5
|
|
190
190
|
# 1..5.each(1,2) { |e| ... } #=> 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
|
|
191
191
|
#
|
|
192
|
-
# @
|
|
192
|
+
# @deprecated The +n+ and +d+ arguments. Use +interval.step(n,d).each+ instead.
|
|
193
|
+
# Scheduled for removal after 2027-09-30.
|
|
193
194
|
def each(n=nil, d=nil) # :yield:
|
|
194
195
|
if n
|
|
195
|
-
warn "
|
|
196
|
-
"
|
|
196
|
+
warn "Interval#each(n, d) is deprecated. Use interval.step(n, d).each instead. " \
|
|
197
|
+
"It will be removed after 2027-09-30.", uplevel: 1
|
|
197
198
|
else
|
|
198
199
|
n = 1
|
|
199
200
|
end
|
|
@@ -256,7 +257,7 @@ class Interval
|
|
|
256
257
|
end
|
|
257
258
|
end
|
|
258
259
|
else
|
|
259
|
-
|
|
260
|
+
to_enum(:step, n, d)
|
|
260
261
|
end
|
|
261
262
|
end
|
|
262
263
|
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
# @deprecated Monkey-patching require/load globally is dangerous.
|
|
2
|
-
|
|
2
|
+
# Scheduled for removal after 2027-09-30.
|
|
3
|
+
warn "facets/load_monitor is deprecated. It monkey-patches require/load globally. It will be removed after 2027-09-30.", uplevel: 1
|