yieldable 0.1.0 → 0.1.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/README.md +32 -21
- data/lib/yieldable/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: 79e8cb644aa929ab313099282285e9f3aa2db151144efc8b07ff4a774fccc80d
|
4
|
+
data.tar.gz: a175016151807bad144be44ad951ee561629f697d4b8ef009f796d52ef084b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e90acbbd5aeb4e9bfcca226f1d3850f8e631df9ee1241775ded0d72d63b87210b6565923ef39c3c91fe2b1430476ecdc3f5c7af7a2396e7235d1ba235c9378f
|
7
|
+
data.tar.gz: c356ff0c2af1ffd8dac446667dcb12079abcc4cf36bebafdc83e834245316af9ebedb888f5f6ca4c8f33f460d619c6f0a5a566b0717a06f9b12f4270070e5fd0
|
data/README.md
CHANGED
@@ -4,7 +4,9 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
|
|
4
4
|
|
5
5
|
Yieldable is meta-mixin, which makes your module, class or it's instance to respond to method +to_proc+, for example, to easily build instances during iteration:
|
6
6
|
|
7
|
-
|
7
|
+
```ruby
|
8
|
+
["1", "2", "3"].map(&SomeObject)
|
9
|
+
```
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
@@ -24,36 +26,45 @@ Or install it yourself as:
|
|
24
26
|
|
25
27
|
## Usage
|
26
28
|
|
27
|
-
It is 2 different ways to use this module:
|
29
|
+
It is 2 different ways to use this module: `extend` or `prepend` it to your class.
|
28
30
|
|
29
|
-
|
31
|
+
### `extend Yieldable`
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
```ruby
|
34
|
+
class SomeObject
|
35
|
+
extend Yieldable
|
36
|
+
# => singleton_class.to_proc = SomeObject.method(:call).to_proc
|
37
|
+
end
|
38
|
+
```
|
34
39
|
|
35
|
-
This way defines an attribute reader
|
36
|
-
It sets a proc only once for a class, so it will not generate a new
|
37
|
-
every time, like if you would use just a
|
38
|
-
By default it uses the
|
39
|
-
can change the source method name by using brackets:
|
40
|
+
This way defines an attribute reader `#to_proc` in a singleton class.
|
41
|
+
It sets a proc only once for a class, so it will not generate a new `Proc` object
|
42
|
+
every time, like if you would use just a `method(:call).to_proc`.
|
43
|
+
By default it uses the `call` class method as a source method for a proc.
|
40
44
|
|
41
|
-
|
42
|
-
extend Yieldable[:new] # => singleton_class.to_proc = SomeObject.method(:new).to_proc
|
43
|
-
end
|
45
|
+
You can change the source method name by using brackets:
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
+
```ruby
|
48
|
+
class SomeObject
|
49
|
+
extend Yieldable[:new]
|
50
|
+
# => singleton_class.to_proc = SomeObject.method(:new).to_proc
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
It's better to ensure that a source method is defined _before_ extending a class with `Yieldable`.
|
55
|
+
In the other way it will add the `Yieldable::WaitMethodDefinition.singletone_method_added` hook and wait. After a source method
|
47
56
|
will be added, the hook method will be removed.
|
48
57
|
|
49
|
-
You can avoid to removing the hook with an optional
|
58
|
+
You can avoid to removing the hook with an optional `once: false` passed into the brackets:
|
50
59
|
|
51
|
-
|
60
|
+
```ruby
|
61
|
+
extend Yieldable[:new, once: false]
|
62
|
+
```
|
52
63
|
|
53
|
-
|
64
|
+
### `prepend Yieldable`
|
54
65
|
|
55
|
-
This way defines a
|
56
|
-
each object. You can also use a brackets like within an
|
66
|
+
This way defines a `#to_proc` instance method once for a class, but a proc will be generated once for
|
67
|
+
each object. You can also use a brackets like within an `extend` way.
|
57
68
|
|
58
69
|
|
59
70
|
## Development
|
data/lib/yieldable/version.rb
CHANGED