ioughta 0.2.0 → 0.2.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 +18 -19
- data/lib/ioughta/version.rb +1 -1
- data/lib/ioughta.rb +4 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c12c98fe08970c112e895a81c1a235bfc89c34b
|
4
|
+
data.tar.gz: 69c50f6794139a6ccb84c51630a418ef33381eb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8ee63a12106312f5701f9ddc2b7c2ded8b77e8febcb19a16ee94205de2ad4fcf290f75da6b8b1448e92e0a3ebfec5b977d01f3e395e83853b969464d384d6dc
|
7
|
+
data.tar.gz: 1a9382fdfdf9c4a57bdb58eb12e3f373d7db4e42e93922cb85b2e9174ccffb86e8de3341bb6b5a78e59bf042da657d052a41514ba4d8589f44fca975fc9e426b
|
data/README.md
CHANGED
@@ -38,16 +38,16 @@ Object.ioughta_const(
|
|
38
38
|
IG_STRAWBERRIES # => 8
|
39
39
|
```
|
40
40
|
|
41
|
-
Or, perhaps a
|
41
|
+
Or, perhaps a bit more Rubyishly:
|
42
42
|
|
43
43
|
```ruby
|
44
|
-
IG = Object.ioughta_hash(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
).freeze
|
44
|
+
IG = Object.ioughta_hash(->(i) { 1 << i }, %i[
|
45
|
+
eggs
|
46
|
+
chocolate
|
47
|
+
nuts
|
48
|
+
strawberries
|
49
|
+
shellfish
|
50
|
+
]).freeze
|
51
51
|
|
52
52
|
IG[:strawberries] # => 8
|
53
53
|
```
|
@@ -120,10 +120,10 @@ You can also pass the lambda as the first argument:
|
|
120
120
|
Object.ioughta_const ->(i) { 1 << (10 * i) }, %i[_ KB MB GB TB PB EB ZB YB]
|
121
121
|
```
|
122
122
|
|
123
|
-
Or even a block, instead of a lambda:
|
123
|
+
Or even pass a block, instead of a lambda:
|
124
124
|
|
125
125
|
```ruby
|
126
|
-
BYTES = Object.ioughta_hash(%i[_ KB MB GB TB PB EB ZB YB]) { |i| 1 << (10 * i) }
|
126
|
+
BYTES = Object.ioughta_hash(%i[_ KB MB GB TB PB EB ZB YB]) { |i| 1 << (10 * i) }.freeze
|
127
127
|
```
|
128
128
|
|
129
129
|
The only major feature missing from the Go implementation is the ability to
|
@@ -148,14 +148,14 @@ require 'ioughta'
|
|
148
148
|
module MyFileUtils
|
149
149
|
include Ioughta
|
150
150
|
|
151
|
-
iota_const
|
152
|
-
iota_const
|
151
|
+
iota_const ->(b) { 1 << b }, %i[EXECUTE WRITE READ]
|
152
|
+
iota_const ->(b) { 1 << b }, %i[TACKY SETGID SETUID]
|
153
153
|
|
154
|
-
|
155
|
-
MASK = iota_hash(
|
154
|
+
OFFSET = iota_hash(->(d) { d * 3 }, %i[other group user special]).freeze
|
155
|
+
MASK = iota_hash(OFFSET.keys) { |_, key| 7 << OFFSET[key] }.freeze
|
156
156
|
|
157
157
|
def self.mask_and_shift(mode, field)
|
158
|
-
(mode & MASK[field]) >>
|
158
|
+
(mode & MASK[field]) >> OFFSET[field]
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -163,14 +163,13 @@ MyFileUtils.mask_and_shift(0644, :user) & MyFileUtils::EXECUTE # => 0
|
|
163
163
|
MyFileUtils.mask_and_shift(01777, :special) & MyFileUtils::TACKY # => 1
|
164
164
|
```
|
165
165
|
|
166
|
-
One note on the above: the lambda can take the key at the current
|
167
|
-
an optional second argument.
|
166
|
+
One note on the above: the lambda (or block) can take the key at the current
|
167
|
+
iteration as an optional second argument.
|
168
168
|
|
169
169
|
## Development
|
170
170
|
|
171
171
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
172
|
-
`rake spec` to run the tests.
|
173
|
-
prompt that will allow you to experiment.
|
172
|
+
`rake spec` to run the tests.
|
174
173
|
|
175
174
|
To install this gem onto your local machine, run `bundle exec rake install`. To
|
176
175
|
release a new version, update the version number in `version.rb`, and then run
|
data/lib/ioughta/version.rb
CHANGED
data/lib/ioughta.rb
CHANGED
@@ -23,10 +23,6 @@ module Ioughta
|
|
23
23
|
DEFAULT_LAMBDA = proc(&:itself)
|
24
24
|
SKIP_SYMBOL = :_
|
25
25
|
|
26
|
-
def lazy_iota
|
27
|
-
(0..Float::INFINITY).lazy
|
28
|
-
end
|
29
|
-
|
30
26
|
def pair(data, &block)
|
31
27
|
data = data.flatten
|
32
28
|
lam =
|
@@ -38,7 +34,7 @@ module Ioughta
|
|
38
34
|
DEFAULT_LAMBDA
|
39
35
|
end
|
40
36
|
|
41
|
-
|
37
|
+
(0..Float::INFINITY).lazy.each do |i|
|
42
38
|
if i % 2 != 0
|
43
39
|
if data[i].respond_to?(:call)
|
44
40
|
lam = data[i]
|
@@ -53,10 +49,10 @@ module Ioughta
|
|
53
49
|
end
|
54
50
|
|
55
51
|
def each_resolved_pair(data)
|
56
|
-
return enum_for(
|
52
|
+
return enum_for(__method__, data) { data.length / 2 } unless block_given?
|
57
53
|
|
58
|
-
data.each_slice(2).
|
59
|
-
val = lam.
|
54
|
+
data.each_slice(2).with_index do |(nom, lam), iota|
|
55
|
+
val = lam.call(*[iota, nom].take(lam.arity.abs))
|
60
56
|
next if nom == SKIP_SYMBOL
|
61
57
|
yield nom, val
|
62
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ioughta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Pastore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|