block-is-hash 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de642563a07a56fabb80dc465da7ff0677214ed2
4
+ data.tar.gz: 47a6a8be1d8fcc63707bb03af04b6318847731f9
5
+ SHA512:
6
+ metadata.gz: f78e90fcc4bbbc88344796e37456284614e6e7ff3f4d002277afcb7988262e0accfd13c37b934dfcda4b5ea32a31ad4ef92d6350167d65c50805d87734d850ac
7
+ data.tar.gz: 9faf115fad0c7443c163d8a58ac27d3b570164bef8366026fc2a7010a24728471241db3f0e2d604f9802652c4f361275e0e3d5f629c25b77a721e91f225aa867
@@ -0,0 +1 @@
1
+ require_relative 'block-is-hash/block_is_hash'
@@ -0,0 +1,7 @@
1
+ require_relative 'blockishash'
2
+
3
+
4
+
5
+ def block_is_hash repeats, &block
6
+ BlockIsHash.new(repeats, &block).to_hash
7
+ end
@@ -0,0 +1,31 @@
1
+ class BlockIsHash
2
+ def initialize repeats, &block
3
+ @repeats = repeats
4
+ @hash = {}
5
+ instance_eval(&block)
6
+ end
7
+
8
+ def method_missing name, *args, &block
9
+ if not (args or block)
10
+ @hash[name]
11
+ end
12
+
13
+ if block
14
+ args.push BlockIsHash.new(@repeats, &block).to_hash
15
+ end
16
+
17
+ value = args.length == 1 ? args[0] : args
18
+
19
+ if @repeats.include? name and @hash.include? name
20
+ @hash[name].push value
21
+ elsif @repeats.include? name
22
+ @hash[name] = [value]
23
+ else
24
+ @hash[name] = value
25
+ end
26
+ end
27
+
28
+ def to_hash
29
+ @hash
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: block-is-hash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yota Toyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: block-to-hash converter
14
+ email: raviqqe@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/block-is-hash.rb
20
+ - lib/block-is-hash/block_is_hash.rb
21
+ - lib/block-is-hash/blockishash.rb
22
+ homepage: https://github.com/raviqqe/block-is-hash
23
+ licenses:
24
+ - Unlicense
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Block is Hash
46
+ test_files: []