sleeping_king_studios-tools 0.7.0 → 0.7.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +24 -0
- data/lib/sleeping_king_studios/tools/core_tools.rb +13 -0
- data/lib/sleeping_king_studios/tools/hash_tools.rb +11 -0
- data/lib/sleeping_king_studios/tools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 694e8a5ab01a8bbe5c689954d0c00a70045f13cd
|
|
4
|
+
data.tar.gz: e6421ef4c5f581125590ef984c3b0f1281e45a36
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 113e19e8b5e5f37906c3bd6dfa05e3bd7f400f3159d13b335128d40acaae22f6426bcd414bed58891661a21914962b98bcc5c9c4cf14d6819f5e4cd62e1c46d7
|
|
7
|
+
data.tar.gz: 58b378e8326afd2ed60ad1487301c9e4e117bc6709c61543ff50a36b4805e432cd90f948eed78c0a710d11476115d4c31d51d4365ec5a9affc135ab2bbe70b81
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -187,6 +187,14 @@ Prints a deprecation warning.
|
|
|
187
187
|
ObjectTools#old_method was deprecated in version 0.1.0.
|
|
188
188
|
called from /path/to/file.rb:4: in something_or_other
|
|
189
189
|
|
|
190
|
+
#### `#empty_binding`
|
|
191
|
+
|
|
192
|
+
Generates an empty Binding object. Note that this binding object still has
|
|
193
|
+
access to Object methods and constants - it is **not** eval-safe.
|
|
194
|
+
|
|
195
|
+
CoreTools.empty_binding
|
|
196
|
+
#=> Binding
|
|
197
|
+
|
|
190
198
|
#### `#require_each`
|
|
191
199
|
|
|
192
200
|
Takes a file pattern or a list of file names and requires each file.
|
|
@@ -262,6 +270,22 @@ Freezes the hash and performs a deep freeze on each hash key and value.
|
|
|
262
270
|
hsh[:one].frozen?
|
|
263
271
|
#=> true
|
|
264
272
|
|
|
273
|
+
#### `#generate_binding`
|
|
274
|
+
|
|
275
|
+
Generates a Binding object, with the hash converted to local variables in the
|
|
276
|
+
binding.
|
|
277
|
+
|
|
278
|
+
hsh = { :one => 'one', :two => 'two', :three => 'three' }
|
|
279
|
+
binding = HashTools.generate_binding(hsh)
|
|
280
|
+
#=> Binding
|
|
281
|
+
|
|
282
|
+
binding.local_variable_defined?(:one)
|
|
283
|
+
#=> true
|
|
284
|
+
binding.local_variable_get(:one)
|
|
285
|
+
#=> 'one'
|
|
286
|
+
binding.eval('one')
|
|
287
|
+
#=> 'one'
|
|
288
|
+
|
|
265
289
|
#### `#hash?`
|
|
266
290
|
|
|
267
291
|
Returns true if the object is or appears to be a Hash.
|
|
@@ -33,6 +33,19 @@ module SleepingKingStudios::Tools
|
|
|
33
33
|
Kernel.warn str
|
|
34
34
|
end # method deprecate
|
|
35
35
|
|
|
36
|
+
# Generates an empty Binding object with a BasicObject as the receiver.
|
|
37
|
+
#
|
|
38
|
+
# @return [Binding] The empty binding object.
|
|
39
|
+
def empty_binding
|
|
40
|
+
context = Object.new
|
|
41
|
+
|
|
42
|
+
def context.binding
|
|
43
|
+
Kernel.instance_method(:binding).bind(self).call
|
|
44
|
+
end # singleton method binding
|
|
45
|
+
|
|
46
|
+
context.binding
|
|
47
|
+
end # method empty_binding
|
|
48
|
+
|
|
36
49
|
# Expands each file pattern and requires each file.
|
|
37
50
|
#
|
|
38
51
|
# @param file_patterns [Array] The files to require.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'sleeping_king_studios/tools'
|
|
4
4
|
require 'sleeping_king_studios/tools/array_tools'
|
|
5
|
+
require 'sleeping_king_studios/tools/core_tools'
|
|
5
6
|
require 'sleeping_king_studios/tools/object_tools'
|
|
6
7
|
|
|
7
8
|
module SleepingKingStudios::Tools
|
|
@@ -72,6 +73,16 @@ module SleepingKingStudios::Tools
|
|
|
72
73
|
end # each
|
|
73
74
|
end # method deep_freeze
|
|
74
75
|
|
|
76
|
+
def generate_binding hsh
|
|
77
|
+
require_hash! hsh
|
|
78
|
+
|
|
79
|
+
CoreTools.empty_binding.tap do |binding|
|
|
80
|
+
hsh.each do |key, value|
|
|
81
|
+
binding.local_variable_set key, value
|
|
82
|
+
end # each
|
|
83
|
+
end # tap
|
|
84
|
+
end # method generate_binding
|
|
85
|
+
|
|
75
86
|
# Returns true if the object is or appears to be a Hash.
|
|
76
87
|
#
|
|
77
88
|
# @param hsh [Object] The object to test.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sleeping_king_studios-tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rob "Merlin" Smith
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-05-
|
|
11
|
+
date: 2017-05-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|