hashslice 1.0.7 → 1.0.8
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/CHANGES +5 -0
- data/README +2 -3
- data/Rakefile +27 -23
- data/hashslice.gemspec +17 -18
- data/lib/hashslice.rb +59 -59
- data/test/test_hashslice.rb +1 -1
- metadata +29 -13
data/CHANGES
CHANGED
data/README
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
Slicing for Ruby hashes.
|
3
3
|
|
4
4
|
= Installation
|
5
|
-
|
6
|
-
rake install
|
5
|
+
gem install hashslice
|
7
6
|
|
8
7
|
= Synopsis
|
9
8
|
require 'hashslice'
|
@@ -36,7 +35,7 @@
|
|
36
35
|
If there are more values than keys, the extra values are dropped.
|
37
36
|
|
38
37
|
= Copyright
|
39
|
-
Copyright (c) 2001-
|
38
|
+
Copyright (c) 2001-2011, The FaerieMUD Consortium and Daniel J. Berger.
|
40
39
|
All rights reserved.
|
41
40
|
|
42
41
|
= License
|
data/Rakefile
CHANGED
@@ -1,23 +1,27 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/clean'
|
3
|
-
require 'rake/testtask'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
desc "Install the hashslice library as a gem"
|
16
|
-
task :
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
CLEAN.include("**/*.gem", "**/*.rbc")
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
|
9
|
+
desc 'Build the hashslice gem'
|
10
|
+
task :create => [:clean] do
|
11
|
+
spec = eval(IO.read('hashslice.gemspec'))
|
12
|
+
Gem::Builder.new(spec).build
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Install the hashslice library as a gem"
|
16
|
+
task :install => [:create] do
|
17
|
+
file = Dir["*.gem"].first
|
18
|
+
sh "gem install #{file}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Rake::TestTask.new do |t|
|
23
|
+
t.warning = true
|
24
|
+
t.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
task :default => :test
|
data/hashslice.gemspec
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
|
4
|
+
gem.name = 'hashslice'
|
5
|
+
gem.version = '1.0.8'
|
6
|
+
gem.authors = ['Daniel J. Berger', 'Michael Granger']
|
7
|
+
gem.license = 'Artistic 2.0'
|
8
|
+
gem.email = 'djberg96@gmail.com'
|
9
|
+
gem.homepage = 'http://www.rubyforge.org/projects/shards'
|
10
|
+
gem.summary = "Adds hash slicing to Ruby's Hash class"
|
11
|
+
gem.test_file = 'test/test_hashslice.rb'
|
12
|
+
gem.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
gem.rubyforge_project = 'shards'
|
15
|
+
gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
17
16
|
|
18
|
-
|
17
|
+
gem.add_development_dependency('test-unit', '>= 2.1.0')
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
gem.description = <<-EOF
|
20
|
+
The hashslice library adds builtin hash slicing to Ruby's Hash class.
|
21
|
+
This lets you reference, or assign to, multiple hash keys simultaneously
|
22
|
+
via the Hash#[] and Hash#[]= methods, respectively.
|
23
|
+
EOF
|
25
24
|
end
|
data/lib/hashslice.rb
CHANGED
@@ -1,65 +1,65 @@
|
|
1
1
|
class Hash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# The version of the hashslice library
|
6
|
-
VERSION_HASHSLICE = '1.0.7'
|
2
|
+
alias href []
|
3
|
+
alias hset []=
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
# Examples:
|
12
|
-
#
|
13
|
-
# hash = {'a' => 1, 'b' => 2, 'c' => 3}
|
14
|
-
# hash['a'] -> 1
|
15
|
-
# hash['a', 'c'] -> [1, 3]
|
16
|
-
#
|
17
|
-
def [](*args)
|
18
|
-
if args.length == 1
|
19
|
-
href(args[0])
|
20
|
-
else
|
21
|
-
args.map{ |k| href(k) }
|
22
|
-
end
|
23
|
-
end
|
5
|
+
# The version of the hashslice library
|
6
|
+
VERSION_HASHSLICE = '1.0.8'
|
24
7
|
|
25
|
-
|
8
|
+
# Retrieve a hash slice. If a single key is provided, returns a single
|
9
|
+
# value. If multiple keys are provided, an array of values is returned.
|
10
|
+
#
|
11
|
+
# Examples:
|
12
|
+
#
|
13
|
+
# hash = {'a' => 1, 'b' => 2, 'c' => 3}
|
14
|
+
# hash['a'] -> 1
|
15
|
+
# hash['a', 'c'] -> [1, 3]
|
16
|
+
#
|
17
|
+
def [](*args)
|
18
|
+
if args.length == 1
|
19
|
+
href(args[0])
|
20
|
+
else
|
21
|
+
args.map{ |k| href(k) }
|
22
|
+
end
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
# Returns a sub-hash of the current hash.
|
54
|
-
#
|
55
|
-
# Example:
|
56
|
-
#
|
57
|
-
# hash = {'a' => 1, 'b' => 2, 'c' => 3}
|
58
|
-
# hash.hash_of('a', 'b') -> {'a' => 1, 'b' => 2}
|
59
|
-
#
|
60
|
-
def hash_of(*args)
|
61
|
-
temp = {}
|
62
|
-
args.map{ |k| temp[k] = href(k) }
|
63
|
-
temp
|
25
|
+
alias slice []
|
26
|
+
|
27
|
+
# Hash slice assignment. You can assign a list of values to a list of keys
|
28
|
+
# in a single operation on a one for one basis.
|
29
|
+
#
|
30
|
+
# If the number of keys exceeds the number of values, the remaining keys
|
31
|
+
# are assigned a value of nil.
|
32
|
+
#
|
33
|
+
# If the number of values exceeds the number of keys, the extra values are
|
34
|
+
# dropped.
|
35
|
+
#
|
36
|
+
# Examples:
|
37
|
+
#
|
38
|
+
# hash['a'] = 1, 2 -> {a => [1, 2]}
|
39
|
+
# hash['a', 'b'] = 3, 4 -> {a => 3, b => 4}
|
40
|
+
# hash['a', 'b'] = 5 -> {a => 5, b => nil}
|
41
|
+
# hash['a', 'b'] = 3, 4, 5 -> {a => 3, b => 4}
|
42
|
+
#
|
43
|
+
def []=(*args)
|
44
|
+
if args.length <= 2
|
45
|
+
hset(*args)
|
46
|
+
else
|
47
|
+
values = args.pop # Last arg is the value. The rest are keys.
|
48
|
+
values = [values] unless values.is_a?(Array)
|
49
|
+
args.each_index{ |i| hset(args[i], values[i]) }
|
50
|
+
end
|
64
51
|
end
|
52
|
+
|
53
|
+
# Returns a sub-hash of the current hash.
|
54
|
+
#
|
55
|
+
# Example:
|
56
|
+
#
|
57
|
+
# hash = {'a' => 1, 'b' => 2, 'c' => 3}
|
58
|
+
# hash.hash_of('a', 'b') -> {'a' => 1, 'b' => 2}
|
59
|
+
#
|
60
|
+
def hash_of(*args)
|
61
|
+
temp = {}
|
62
|
+
args.map{ |k| temp[k] = href(k) }
|
63
|
+
temp
|
64
|
+
end
|
65
65
|
end
|
data/test/test_hashslice.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashslice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 8
|
10
|
+
version: 1.0.8
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Daniel J. Berger
|
@@ -10,20 +16,25 @@ autorequire:
|
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date:
|
14
|
-
default_executable:
|
19
|
+
date: 2011-08-31 00:00:00 Z
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: test-unit
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
21
26
|
requirements:
|
22
27
|
- - ">="
|
23
28
|
- !ruby/object:Gem::Version
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
hash: 11
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
version: 2.1.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: " The hashslice library adds builtin hash slicing to Ruby's Hash class.\n This lets you reference, or assign to, multiple hash keys simultaneously\n via the Hash#[] and Hash#[]= methods, respectively.\n"
|
27
38
|
email: djberg96@gmail.com
|
28
39
|
executables: []
|
29
40
|
|
@@ -41,7 +52,6 @@ files:
|
|
41
52
|
- Rakefile
|
42
53
|
- README
|
43
54
|
- test/test_hashslice.rb
|
44
|
-
has_rdoc: true
|
45
55
|
homepage: http://www.rubyforge.org/projects/shards
|
46
56
|
licenses:
|
47
57
|
- Artistic 2.0
|
@@ -51,21 +61,27 @@ rdoc_options: []
|
|
51
61
|
require_paths:
|
52
62
|
- lib
|
53
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
54
65
|
requirements:
|
55
66
|
- - ">="
|
56
67
|
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
57
71
|
version: "0"
|
58
|
-
version:
|
59
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
60
74
|
requirements:
|
61
75
|
- - ">="
|
62
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
63
80
|
version: "0"
|
64
|
-
version:
|
65
81
|
requirements: []
|
66
82
|
|
67
83
|
rubyforge_project: shards
|
68
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.8.10
|
69
85
|
signing_key:
|
70
86
|
specification_version: 3
|
71
87
|
summary: Adds hash slicing to Ruby's Hash class
|