of 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/of/method.rb +4 -1
- data/lib/of/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 499b04d6aab178e1c40380ce36e94152c0c6a074
|
4
|
+
data.tar.gz: 3e041852cff83be3fac8bb115ca9bcbac39622c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f902ff86405777e99a35654be69599c6c834fe5850d487c7a377cef04009786e1ba412ec7fdb4a0d0f616c1a7d43837f99a181c307ace0a473fe8c1407589fe
|
7
|
+
data.tar.gz: ad0d6cbc858203c5375465cff30cbe747ad467678b4d19156581c13073d492030dda843d770e63f1401daa90d4418a1628ff336eae6df5c3ec603a12800e645d
|
data/README.md
CHANGED
@@ -21,12 +21,21 @@ $ gem install of
|
|
21
21
|
```
|
22
22
|
|
23
23
|
## Basic Usage
|
24
|
+
|
25
|
+
### Block Syntax
|
24
26
|
```ruby
|
25
27
|
def 7_of_9
|
26
28
|
7.of { 9 } # => [9, 9, 9, 9, 9, 9, 9, 9]
|
27
29
|
end
|
28
30
|
```
|
29
31
|
|
32
|
+
### Class Syntax
|
33
|
+
```ruby
|
34
|
+
def 3_objects
|
35
|
+
3.of(Object) # => [#<Object:0x007fb0db8b75c0>, #<Object:0x007fb0db8b7548>, #<Object:0x007fb0db8b74f8>]
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
30
39
|
## Usage with Refinements
|
31
40
|
```ruby
|
32
41
|
class MyClass
|
data/lib/of/method.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Of
|
2
2
|
METHOD = proc do
|
3
|
-
def of(&block)
|
3
|
+
def of(klass=nil, &block)
|
4
|
+
klass || block || raise(ArgumentError, 'must provide a `Class` or block')
|
5
|
+
block || klass.respond_to?(:new) || raise(ArgumentError, 'class must respond to `.new`')
|
6
|
+
block = proc { klass.new } if klass.is_a? Class
|
4
7
|
self.times.map(&block)
|
5
8
|
end
|
6
9
|
end
|
data/lib/of/version.rb
CHANGED