invokable 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8285e8008ed711e2898713904adabd60c274f60a5d21b0995443c62bc9bd5ad9
4
- data.tar.gz: 935b77cfdc76c309cd7bb6866fb85cfa823f8fa7cefc399fd7b6e6e1018b7f83
3
+ metadata.gz: b5a26558a5514a4af779fba9fbc1d015e88fa9c9f2c6a12d88aa274c3307e421
4
+ data.tar.gz: 633c511d7f4f3509b275b3db38e246303ceed19db80c5dfbbb90df889c7d930f
5
5
  SHA512:
6
- metadata.gz: 8d501dca816dbdf3b49381f55b771564975886a1f3cd2d96946142301abaf833e5733ca77741e45ab3ec9975878b61022640d8c90226426a5e25c79d28734709
7
- data.tar.gz: c4719b7d18dd692b933c2648504cd511136481c2256b0c670ecd09e1adbf7d7a9e31b17b2bb45b8ef7cf725a5063dd970c6344efef7c84c0fd3c4d269f30bfa5
6
+ metadata.gz: 51e7fdfc72e240d55189d69764f9fc8edb35e607eaa1374027d7c1a9478a6428f1bf28aee44971ba8929a75598a4a696a6f02f6370e73b98e0cc03f6cd34d64d
7
+ data.tar.gz: b553bb218572e6f09af06680fb6c8d3774e3dac8e466f08400d9faf16c74e26cb23f1b00699901caf9db1bf60966d293a01255edfe6ebf9e31dac241c0e107d4
@@ -1,5 +1,26 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Invokable::call
6
+
7
+ When all the arguments of the initializer are passed and the instance method is zero arity the instance method will be called.
8
+
9
+ ```ruby
10
+ class Greeter
11
+ def initialize(name)
12
+ @name = name
13
+ end
14
+
15
+ def call
16
+ "Hello #{name}"
17
+ end
18
+ end
19
+
20
+ Greeter.call("Jane") # => "Hello Jane"
21
+ Greeter.call("John") # => #<Greeter ...> (before 0.7.1)
22
+ ```
23
+
3
24
  ## 0.7.0
4
25
 
5
26
  - Added helper methods `juxtapose`, `knit`, `compose`, `identity`, `always`, `guarded`, `partial`, and `coerce`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invokable (0.7.0)
4
+ invokable (0.7.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -3,40 +3,10 @@
3
3
 
4
4
  # Invokable
5
5
 
6
- Objects are functions! Treat any Object, Class, Hashes, Arrays, and Sets as Procs (like Enumerable but for Procs)
6
+ Objects are functions! Treat any Object or Class as a Proc (like Enumerable but for Procs)
7
7
 
8
8
  ## Synopsis
9
9
 
10
- Hashes can be treated as functions of their keys
11
-
12
- ```ruby
13
- require 'invokable'
14
- require 'invokable/hash'
15
-
16
- number_names = { 1 => "One", 2 => "Two", 3 => "Three" }
17
- [1, 2, 3, 4].map(&number_names) # => ["One", "Two", "Three", nil]
18
- ```
19
-
20
- Arrays can be treated as functions of their indexes
21
-
22
- ```ruby
23
- require 'invokable'
24
- require 'invokable/array'
25
-
26
- alpha = ('a'..'z').to_a
27
- [1, 2, 3, 4].map(&alpha) # => ["b", "c", "d", "e"]
28
- ```
29
-
30
- Sets can be treated as predicates
31
-
32
- ```ruby
33
- require 'invokable'
34
- require 'invokable/set'
35
-
36
- favorite_numbers = Set[3, Math::PI]
37
- [1, 2, 3, 4].select(&favorite_numbers) # => [3]
38
- ```
39
-
40
10
  Objects that enclose state, can be treated as automatically curried functions.
41
11
 
42
12
  ```ruby
@@ -75,7 +45,7 @@ class FilterRecords
75
45
  @params = params
76
46
  end
77
47
 
78
- def call(params)
48
+ def call(records)
79
49
  # do filtering return records
80
50
  end
81
51
  end
@@ -119,10 +89,41 @@ end
119
89
  Transformer.call([:a, :b, :c, :d]) # => {:a => "A", :b => "B", :c => "C", :d => "D"}
120
90
  ```
121
91
 
92
+ Hashes can be treated as functions of their keys
93
+
94
+ ```ruby
95
+ require 'invokable'
96
+ require 'invokable/hash'
97
+
98
+ number_names = { 1 => "One", 2 => "Two", 3 => "Three" }
99
+ [1, 2, 3, 4].map(&number_names) # => ["One", "Two", "Three", nil]
100
+ ```
101
+
102
+ Arrays can be treated as functions of their indexes
103
+
104
+ ```ruby
105
+ require 'invokable'
106
+ require 'invokable/array'
107
+
108
+ alpha = ('a'..'z').to_a
109
+ [1, 2, 3, 4].map(&alpha) # => ["b", "c", "d", "e"]
110
+ ```
111
+
112
+ Sets can be treated as predicates
113
+
114
+ ```ruby
115
+ require 'invokable'
116
+ require 'invokable/set'
117
+
118
+ favorite_numbers = Set[3, Math::PI]
119
+ [1, 2, 3, 4].select(&favorite_numbers) # => [3]
120
+ ```
121
+
122
122
  Use as much or a little as you need
123
123
 
124
124
  ```ruby
125
125
  require 'invokable' # loads Invokable module
126
+ require 'invokable/helpers' # loads Invokable::Helpers module
126
127
  require 'invokable/hash' # loads hash patch
127
128
  require 'invokable/array' # loads array patch
128
129
  require 'invokable/set' # loads set patch
@@ -151,6 +152,10 @@ Or install it yourself as:
151
152
 
152
153
  > gem install invokable
153
154
 
155
+ ## API Documentation
156
+
157
+ [https://www.rubydoc.info/gems/invokable](https://www.rubydoc.info/gems/invokable)
158
+
154
159
  ## See Also
155
160
 
156
161
  - [Closures and Objects are Equivalent](http://wiki.c2.com/?ClosuresAndObjectsAreEquivalent)
@@ -0,0 +1 @@
1
+ #theme: jekyll-theme-minimal
@@ -50,7 +50,7 @@ module Invokable
50
50
  #
51
51
  # @return [Integer]
52
52
  def arity
53
- initializer_arity + instance_method(:call).arity
53
+ initializer_arity + invoker_arity
54
54
  end
55
55
 
56
56
  # Handle automatic currying--will accept either the initializer arity or the total arity of the class. If
@@ -61,8 +61,9 @@ module Invokable
61
61
  #
62
62
  # @see arity
63
63
  def call(*args)
64
- return new.call if arity == 0
65
- return new(*args) if args.length == initializer_arity
64
+ return new.call if arity == 0
65
+ return new(*args).call if args.length == initializer_arity && invoker_arity == 0
66
+ return new(*args) if args.length == initializer_arity
66
67
 
67
68
  if args.length == arity
68
69
  init_args = args.slice(0, initializer_arity)
@@ -78,5 +79,9 @@ module Invokable
78
79
  def initializer_arity
79
80
  instance_method(:initialize).arity
80
81
  end
82
+
83
+ def invoker_arity
84
+ instance_method(:call).arity
85
+ end
81
86
  end
82
87
  end
@@ -1,3 +1,3 @@
1
1
  module Invokable
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invokable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delon Newman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-15 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,6 +69,7 @@ files:
69
69
  - LICENSE.txt
70
70
  - README.md
71
71
  - Rakefile
72
+ - _config.yml
72
73
  - invokable.gemspec
73
74
  - lib/core_ext.rb
74
75
  - lib/invokable.rb
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
107
  - !ruby/object:Gem::Version
107
108
  version: '0'
108
109
  requirements: []
109
- rubygems_version: 3.0.8
110
+ rubygems_version: 3.0.6
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: Objects are functions! Treat any Object, Hashes, Arrays and Sets as Procs