ioughta 0.2.0 → 0.2.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
  SHA1:
3
- metadata.gz: 3b152908c1f9d29a440ce0b75dea2aa8304a725f
4
- data.tar.gz: 4d3a0d6e9c75914bbc47ed8dd81f369c1f810cad
3
+ metadata.gz: 0c12c98fe08970c112e895a81c1a235bfc89c34b
4
+ data.tar.gz: 69c50f6794139a6ccb84c51630a418ef33381eb0
5
5
  SHA512:
6
- metadata.gz: b76d09e9c90065bc57f4c820a33c8776d9e069aed1919576f5b7fa018656e14c794fa815ff3dd1bf357956d76345ae4f495b9176604c3c6b796582da67c14393
7
- data.tar.gz: b15f831e6694d08e22015773fcb3207563487fa61300a929f4965cf57d3b1d5d629b9de8b8acc1d8112ff20d71c25b1e039d9cb545d8f7b63480544ef174630e
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 little more Rubyishly:
41
+ Or, perhaps a bit more Rubyishly:
42
42
 
43
43
  ```ruby
44
- IG = Object.ioughta_hash(
45
- :eggs, ->(i) { 1 << i },
46
- :chocolate,
47
- :nuts,
48
- :strawberries,
49
- :shellfish
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 :EXECUTE, ->(b) { 0b1 << b }, :WRITE, :READ
152
- iota_const :TACKY, ->(b) { 0b1 << b }, :SETGID, :SETUID
151
+ iota_const ->(b) { 1 << b }, %i[EXECUTE WRITE READ]
152
+ iota_const ->(b) { 1 << b }, %i[TACKY SETGID SETUID]
153
153
 
154
- SHIFT = iota_hash(:other, ->(d) { d * 3 }, :group, :user, :special).freeze
155
- MASK = iota_hash(:other, ->(_o, key) { 07 << SHIFT[key] }, :group, :user, :special).freeze
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]) >> SHIFT[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 iteration as
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. You can also run `bin/console` for an interactive
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: false
2
2
  module Ioughta
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
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
- lazy_iota.each do |i|
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(:each_resolved_pair, data) unless block_given?
52
+ return enum_for(__method__, data) { data.length / 2 } unless block_given?
57
53
 
58
- data.each_slice(2).with_object(lazy_iota) do |(nom, lam), iota|
59
- val = lam.arity == 2 ? lam.call(iota.next, nom) : lam.call(iota.next)
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.0
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-13 00:00:00.000000000 Z
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler