invokable 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/README.md +2 -3
- data/lib/invokable.rb +6 -5
- data/lib/invokable/array.rb +5 -1
- data/lib/invokable/hash.rb +4 -0
- data/lib/invokable/set.rb +4 -0
- data/lib/invokable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faf0947e19adf5c11f17f5893122d24aa48323807dd364593a38c391e8901c34
|
4
|
+
data.tar.gz: a482d9ddd514251f362c149eca16774b5b4853159eb52c79653c3f5f8df5b9ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d2b9ac66665785662b3ab016981a4c747ab32c88e637cb2bfc2a52e34ed353e5f341a5ef178582e7a3cae584576c341aa88907967cd4722acd07c2cb29d001e
|
7
|
+
data.tar.gz: a89620c1f7127ed27794ef84d45803cbabaf93ceee680edf80a638f4c020551fbde83b3682d8afef70597a692158b157c701d9f3c27b634e5e24476c37f81337
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
invokable (0.2.
|
4
|
+
invokable (0.2.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -26,6 +26,7 @@ GEM
|
|
26
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
27
|
rspec-support (~> 3.9.0)
|
28
28
|
rspec-support (3.9.2)
|
29
|
+
yard (0.9.24)
|
29
30
|
|
30
31
|
PLATFORMS
|
31
32
|
ruby
|
@@ -36,6 +37,7 @@ DEPENDENCIES
|
|
36
37
|
pry
|
37
38
|
rake (~> 10.0)
|
38
39
|
rspec (~> 3.0)
|
40
|
+
yard
|
39
41
|
|
40
42
|
BUNDLED WITH
|
41
43
|
1.17.3
|
data/README.md
CHANGED
@@ -62,7 +62,7 @@ many one method objects out there (e.g. ServiceObjects) that are essentially fun
|
|
62
62
|
|
63
63
|
# API
|
64
64
|
|
65
|
-
## to_proc ->
|
65
|
+
## `to_proc -> Proc`
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
hash = { a: 1, b, 2 }
|
@@ -76,8 +76,7 @@ returning a proc that passes it's arguments to the object's `call` method. When
|
|
76
76
|
loaded `Hash#call` is mapped to `Hash#dig`, `Array#call` is mapped to `Array#at`, and `Set#call`
|
77
77
|
is mapped to `Set#include?`.
|
78
78
|
|
79
|
-
## curry ->
|
80
|
-
## curry(arity) -> a_proc
|
79
|
+
## `curry([arity]) -> Proc`
|
81
80
|
|
82
81
|
Returns a curried proc. If the `arity` is given, it determines the number of arguments.
|
83
82
|
(see [Proc#curry](https://ruby-doc.org/core-2.7.0/Proc.html#method-i-curry)).
|
data/lib/invokable.rb
CHANGED
@@ -4,7 +4,7 @@ require 'invokable/version'
|
|
4
4
|
module Invokable
|
5
5
|
# If object responds to `call` convert into a Proc forwards it's arguments along to `call`.
|
6
6
|
#
|
7
|
-
# @see
|
7
|
+
# @see https://ruby-doc.org/core-2.7.0/Proc.html#method-i-call Proc#call
|
8
8
|
# @return [Proc]
|
9
9
|
def to_proc
|
10
10
|
if respond_to?(:call)
|
@@ -17,14 +17,15 @@ module Invokable
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
# Return a curried proc. If the optional arity argument is given, it determines the number of arguments.
|
20
|
+
# Return a curried proc. If the optional `arity` argument is given, it determines the number of arguments.
|
21
21
|
# A curried proc receives some arguments. If a sufficient number of arguments are supplied, it passes the
|
22
22
|
# supplied arguments to the original proc and returns the result. Otherwise, returns another curried proc
|
23
23
|
# that takes the rest of arguments.
|
24
24
|
#
|
25
|
-
# @see
|
25
|
+
# @see https://ruby-doc.org/core-2.7.0/Proc.html#method-i-curry Proc#curry
|
26
|
+
# @param arity [Number]
|
26
27
|
# @return [Proc]
|
27
|
-
def curry(
|
28
|
-
to_proc.curry(
|
28
|
+
def curry(arity = nil)
|
29
|
+
to_proc.curry(arity)
|
29
30
|
end
|
30
31
|
end
|
data/lib/invokable/array.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require_relative '../invokable'
|
2
2
|
|
3
|
+
# Extend core Array object by aliasing it's `[]` method as `call`,
|
4
|
+
# and including the `Invokable` module.
|
5
|
+
#
|
6
|
+
# @see https://ruby-doc.org/core-2.7.0/Array.html#method-i-5B-5D Array#[]
|
3
7
|
class Array
|
4
8
|
include Invokable
|
5
|
-
alias call
|
9
|
+
alias call []
|
6
10
|
end
|
data/lib/invokable/hash.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require_relative '../invokable'
|
2
2
|
|
3
|
+
# Extend core Hash object by aliasing it's `dig` method as `call`,
|
4
|
+
# and including the `Invokable` module.
|
5
|
+
#
|
6
|
+
# @see https://ruby-doc.org/core-2.7.0/Hash.html#method-i-dig Hash#dig
|
3
7
|
class Hash
|
4
8
|
include Invokable
|
5
9
|
alias call dig
|
data/lib/invokable/set.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'set'
|
2
2
|
require_relative '../invokable'
|
3
3
|
|
4
|
+
# Extend stdlib Set object by aliasing it's `include?` method as `call`,
|
5
|
+
# and including the `Invokable` module.
|
6
|
+
#
|
7
|
+
# @see https://ruby-doc.org/stdlib-2.7.0/libdoc/set/rdoc/Set.html#method-i-include-3F Set#include?
|
4
8
|
class Set
|
5
9
|
include Invokable
|
6
10
|
alias call include?
|
data/lib/invokable/version.rb
CHANGED