ioughta 0.1.0 → 0.2.0
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 +12 -0
- data/lib/ioughta/version.rb +1 -1
- data/lib/ioughta.rb +17 -6
- 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: 3b152908c1f9d29a440ce0b75dea2aa8304a725f
|
4
|
+
data.tar.gz: 4d3a0d6e9c75914bbc47ed8dd81f369c1f810cad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b76d09e9c90065bc57f4c820a33c8776d9e069aed1919576f5b7fa018656e14c794fa815ff3dd1bf357956d76345ae4f495b9176604c3c6b796582da67c14393
|
7
|
+
data.tar.gz: b15f831e6694d08e22015773fcb3207563487fa61300a929f4965cf57d3b1d5d629b9de8b8acc1d8112ff20d71c25b1e039d9cb545d8f7b63480544ef174630e
|
data/README.md
CHANGED
@@ -114,6 +114,18 @@ Object.ioughta_const(
|
|
114
114
|
)
|
115
115
|
```
|
116
116
|
|
117
|
+
You can also pass the lambda as the first argument:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
Object.ioughta_const ->(i) { 1 << (10 * i) }, %i[_ KB MB GB TB PB EB ZB YB]
|
121
|
+
```
|
122
|
+
|
123
|
+
Or even a block, instead of a lambda:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
BYTES = Object.ioughta_hash(%i[_ KB MB GB TB PB EB ZB YB]) { |i| 1 << (10 * i) }
|
127
|
+
```
|
128
|
+
|
117
129
|
The only major feature missing from the Go implementation is the ability to
|
118
130
|
perform parallel assignment in the constant list. We're defining a list of
|
119
131
|
terms, not a list of expressions, so it's not possible to do in Ruby without
|
data/lib/ioughta/version.rb
CHANGED
data/lib/ioughta.rb
CHANGED
@@ -4,14 +4,16 @@ require 'ioughta/version'
|
|
4
4
|
module Ioughta
|
5
5
|
def self.included(base)
|
6
6
|
class << base
|
7
|
-
def ioughta_const(*data)
|
8
|
-
each_resolved_pair(pair(data))
|
7
|
+
def ioughta_const(*data, &block)
|
8
|
+
each_resolved_pair(pair(data, &block)) do |nom, val|
|
9
|
+
const_set(nom, val)
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
alias_method :iota_const, :ioughta_const
|
12
14
|
|
13
|
-
def ioughta_hash(*data)
|
14
|
-
each_resolved_pair(pair(data)).to_h
|
15
|
+
def ioughta_hash(*data, &block)
|
16
|
+
each_resolved_pair(pair(data, &block)).to_h
|
15
17
|
end
|
16
18
|
|
17
19
|
alias_method :iota_hash, :ioughta_hash
|
@@ -25,8 +27,17 @@ module Ioughta
|
|
25
27
|
(0..Float::INFINITY).lazy
|
26
28
|
end
|
27
29
|
|
28
|
-
def pair(data)
|
29
|
-
data
|
30
|
+
def pair(data, &block)
|
31
|
+
data = data.flatten
|
32
|
+
lam =
|
33
|
+
if block
|
34
|
+
block
|
35
|
+
elsif data.first.respond_to?(:call)
|
36
|
+
data.shift
|
37
|
+
else
|
38
|
+
DEFAULT_LAMBDA
|
39
|
+
end
|
40
|
+
|
30
41
|
lazy_iota.each do |i|
|
31
42
|
if i % 2 != 0
|
32
43
|
if data[i].respond_to?(:call)
|