keyword_hash_builder 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.
- checksums.yaml +7 -0
- data/README.md +36 -0
- data/lib/keyword_hash_builder.rb +28 -0
- data/lib/version.rb +3 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40cf4d8018700b35e4e819863c18751068c7d58a
|
4
|
+
data.tar.gz: c7260ccb4b71555ec735a3659f1244171a35c96a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70546043934e5656c361b5b225d61b27c9a6a1a06228b2d0a5c121b86779e272b9f4871de17c80387f759293650839226ceeb5dce994c7cff1d483ecbdde197c
|
7
|
+
data.tar.gz: 4ef8ad7c7e7c4c7e45954ef60f2fb2c81bd681fcd54ceac574bda8b2fb4cc07ef6ab8fdba016357c66e6c417ebac124dbf27d7e944d98b12e99fe98d3bf02e68
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
_gem skeleton generated with [gemmy](http://github.com/maxpleaner/gemmyrb)_
|
2
|
+
|
3
|
+
This provides a syntax somewhat similar to Javascript's shorthand for constructing hashes.
|
4
|
+
|
5
|
+
This code is copied from a stack overflow answer authored by user `akuhn`:
|
6
|
+
|
7
|
+
http://stackoverflow.com/a/41456114/2981429
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
|
13
|
+
1. `gem 'keyword_hash_builder'`
|
14
|
+
|
15
|
+
2. `require 'keyword_hash_builder'`
|
16
|
+
|
17
|
+
3. load patch in one of two ways:
|
18
|
+
1. globally
|
19
|
+
|
20
|
+
KeywordHashBuilder.load_globally
|
21
|
+
|
22
|
+
2. refinement
|
23
|
+
|
24
|
+
# in a class / module definition
|
25
|
+
using KeywordHashBuilder.patch
|
26
|
+
|
27
|
+
4. Use this syntax:
|
28
|
+
|
29
|
+
a = 1
|
30
|
+
b = 2
|
31
|
+
c = String
|
32
|
+
puts `a,b,c`
|
33
|
+
# => { a: 1, b: 2, c: String }
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'debug_inspector'
|
2
|
+
|
3
|
+
|
4
|
+
class KeywordHashBuilder
|
5
|
+
module BacktickPatch
|
6
|
+
def `(str)
|
7
|
+
RubyVM::DebugInspector.open do |inspector|
|
8
|
+
str.split(?,).zip(eval("[#{str}]", inspector.frame_binding(2))).to_h
|
9
|
+
end
|
10
|
+
end
|
11
|
+
refine String do
|
12
|
+
include BacktickPatch
|
13
|
+
end
|
14
|
+
end
|
15
|
+
using BacktickPatch
|
16
|
+
def self.autotest
|
17
|
+
a = 1
|
18
|
+
puts "`a` == #{`a`}"
|
19
|
+
end
|
20
|
+
def self.load_globally
|
21
|
+
Object.include BacktickPatch
|
22
|
+
end
|
23
|
+
def self.patch
|
24
|
+
BacktickPatch
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Gem.find_files("keyword_hash_builder/**/*.rb").each &method(:require)
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keyword_hash_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- maxpleaner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: debug_inspector
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: ''
|
28
|
+
email: maxpleaner@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- lib/keyword_hash_builder.rb
|
35
|
+
- lib/version.rb
|
36
|
+
homepage: https://github.com/maxpleaner/keyword_hash_builder
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.3'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.5.1
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.5.1
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: a shorthand for building hashes, in the manner of javascript
|
60
|
+
test_files: []
|