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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bd946f7ba2d07976031712406bf90ea7c845b6d
4
- data.tar.gz: 323d3409b17d8db6c1e64a7c9bbd664f3d524036
3
+ metadata.gz: 3b152908c1f9d29a440ce0b75dea2aa8304a725f
4
+ data.tar.gz: 4d3a0d6e9c75914bbc47ed8dd81f369c1f810cad
5
5
  SHA512:
6
- metadata.gz: 5efc1fd72d5e450ed3e6ca13022b6d69ded722c9fde75e294bcf5cafc588c2802152b46fef58e651b90f20cb487208692e344f33078072289e9181c78d8069b3
7
- data.tar.gz: 162ddfcede4fe8d9b0182f9a020e6ade3aa126fd030978786fa1a9546a6390db689a7e51df4ccff017e8437b2b0bd69d60c6bb3f962578501e918c42d21ddf2e
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: false
2
2
  module Ioughta
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
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)) { |nom, val| const_set(nom, val) }
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, lam = data.dup, DEFAULT_LAMBDA
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ioughta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Pastore