map 0.0.1 → 1.0.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.
- data/lib/map.rb +25 -21
- metadata +3 -3
data/lib/map.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Map < Hash
|
2
|
-
Version = '0.0
|
2
|
+
Version = '1.0.0' unless defined?(Version)
|
3
3
|
Load = Kernel.method(:load) unless defined?(Load)
|
4
4
|
|
5
5
|
class << Map
|
@@ -10,39 +10,47 @@ class Map < Hash
|
|
10
10
|
# class constructor
|
11
11
|
#
|
12
12
|
def new(*args, &block)
|
13
|
-
map = super(&block)
|
14
|
-
|
15
13
|
case args.size
|
16
14
|
when 0
|
17
|
-
|
15
|
+
super(&block)
|
18
16
|
|
19
17
|
when 1
|
20
|
-
case
|
18
|
+
case args.first
|
21
19
|
when Hash
|
22
|
-
new_from_hash(
|
20
|
+
new_from_hash(args.first)
|
23
21
|
when Array
|
24
|
-
new_from_array(
|
22
|
+
new_from_array(args.first)
|
25
23
|
else
|
26
|
-
new_from_hash(
|
24
|
+
new_from_hash(args.first.to_hash)
|
27
25
|
end
|
28
26
|
|
29
27
|
else
|
30
|
-
new_from_array(args
|
28
|
+
new_from_array(args)
|
31
29
|
end
|
32
|
-
|
33
|
-
map
|
34
30
|
end
|
35
31
|
|
36
|
-
def new_from_hash(hash
|
32
|
+
def new_from_hash(hash)
|
33
|
+
map = new
|
37
34
|
map.update(hash)
|
38
35
|
map
|
39
36
|
end
|
40
37
|
|
41
|
-
def new_from_array(array
|
38
|
+
def new_from_array(array)
|
39
|
+
map = new
|
42
40
|
each_pair(array){|key, val| map[key] = val}
|
43
41
|
map
|
44
42
|
end
|
45
43
|
|
44
|
+
def for(*args, &block)
|
45
|
+
first = args.first
|
46
|
+
|
47
|
+
if(args.size == 1 and block.nil?)
|
48
|
+
return first.to_map if first.respond_to?(:to_map)
|
49
|
+
end
|
50
|
+
|
51
|
+
new(*args, &block)
|
52
|
+
end
|
53
|
+
|
46
54
|
# iterate over arguments in pairs smartly.
|
47
55
|
#
|
48
56
|
def each_pair(*args)
|
@@ -351,6 +359,10 @@ class Map < Hash
|
|
351
359
|
|
352
360
|
# converions
|
353
361
|
#
|
362
|
+
def to_map
|
363
|
+
self
|
364
|
+
end
|
365
|
+
|
354
366
|
def to_hash
|
355
367
|
hash = Hash.new(default)
|
356
368
|
each do |key, val|
|
@@ -378,14 +390,6 @@ class Map < Hash
|
|
378
390
|
def stringify_keys!; self end
|
379
391
|
def symbolize_keys!; self end
|
380
392
|
def to_options!; self end
|
381
|
-
|
382
|
-
def class
|
383
|
-
Hash
|
384
|
-
end
|
385
|
-
|
386
|
-
def __class__
|
387
|
-
Map
|
388
|
-
end
|
389
393
|
end
|
390
394
|
|
391
395
|
module Kernel
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.1
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ara T. Howard
|