arrayextension 0.1.0 → 0.2.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/CHANGELOG +3 -0
- data/VERSION +1 -1
- data/lib/arrayextension.rb +20 -0
- data/spec/arrayextension_spec.rb +44 -0
- metadata +21 -9
data/CHANGELOG
ADDED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.2.0
|
data/lib/arrayextension.rb
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
#
|
|
3
3
|
class Array
|
|
4
4
|
|
|
5
|
+
# Returns an array of symbols corresponding to the elements in the array
|
|
6
|
+
#
|
|
7
|
+
# [].to_symbols # => []
|
|
8
|
+
# %w(collect map sort).to_symbols # => [:collect, :map, :sort]
|
|
9
|
+
# [1,2,3,4,5].to_symbols # => [:"1", :"2", :"3", :"4", :"5"]
|
|
10
|
+
# ['1', nil].to_symbols # => [:'1']
|
|
11
|
+
#
|
|
12
|
+
def to_symbols
|
|
13
|
+
self.compact.collect {|element| element.to_s.to_sym }
|
|
14
|
+
end
|
|
15
|
+
|
|
5
16
|
# Returns a string created by converting each element of the array to a string, separated by \n
|
|
6
17
|
#
|
|
7
18
|
# [].join_cr #=> ""
|
|
@@ -25,6 +36,15 @@ class Array
|
|
|
25
36
|
(1..number_of_elements).to_a.map { random_element }
|
|
26
37
|
end
|
|
27
38
|
|
|
39
|
+
# Return true if element is not include in the list
|
|
40
|
+
#
|
|
41
|
+
# [].not_include?(1) # => true
|
|
42
|
+
# [1].not_include?(1) # => false
|
|
43
|
+
#
|
|
44
|
+
def not_include?(element)
|
|
45
|
+
!self.include?(element)
|
|
46
|
+
end
|
|
47
|
+
|
|
28
48
|
private
|
|
29
49
|
|
|
30
50
|
def random_element
|
data/spec/arrayextension_spec.rb
CHANGED
|
@@ -49,4 +49,48 @@ describe Array do
|
|
|
49
49
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
describe ".to_symbols" do
|
|
53
|
+
|
|
54
|
+
it "should be an empty array when an empty string is given" do
|
|
55
|
+
[].to_symbols.should == []
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should ignore nil items" do
|
|
59
|
+
[nil].to_symbols.should == []
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should return all elements as Symbol for when Strings are given" do
|
|
63
|
+
%w(collect map sort reverse).to_symbols.should == [:collect, :map, :sort, :reverse]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should return all elements as Symbol when Fixnums are given" do
|
|
67
|
+
[1,2,3,4,5].to_symbols.should == [:"1", :"2", :"3", :"4", :"5"]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should return all elements as Symbol when Ranges are given" do
|
|
71
|
+
[(1..5), (6..10)].to_symbols.should == [:"1..5", :"6..10"]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe '.not_include?' do
|
|
77
|
+
|
|
78
|
+
it "should return false if included in the array" do
|
|
79
|
+
[1].not_include?(1).should be_false
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should return false for the true element in the array" do
|
|
83
|
+
[true].not_include?(true).should be_false
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should return true if element is not included in the array" do
|
|
87
|
+
[1,2,3].not_include?(4).should be_true
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should return true if element nil is not included in the array" do
|
|
91
|
+
[true, false].not_include?(nil).should be_true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
|
|
52
96
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: arrayextension
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 2
|
|
8
|
+
- 0
|
|
9
|
+
version: 0.2.0
|
|
5
10
|
platform: ruby
|
|
6
11
|
authors:
|
|
7
12
|
- Vinicius Teles
|
|
@@ -9,19 +14,23 @@ autorequire:
|
|
|
9
14
|
bindir: bin
|
|
10
15
|
cert_chain: []
|
|
11
16
|
|
|
12
|
-
date:
|
|
17
|
+
date: 2010-05-12 00:00:00 -03:00
|
|
13
18
|
default_executable:
|
|
14
19
|
dependencies:
|
|
15
20
|
- !ruby/object:Gem::Dependency
|
|
16
21
|
name: rspec
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
20
24
|
requirements:
|
|
21
25
|
- - ">="
|
|
22
26
|
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 1
|
|
29
|
+
- 2
|
|
30
|
+
- 8
|
|
23
31
|
version: 1.2.8
|
|
24
|
-
|
|
32
|
+
type: :development
|
|
33
|
+
version_requirements: *id001
|
|
25
34
|
description: This gem extends the Ruby class Array with a few useful methods. Just a bit of sugar.
|
|
26
35
|
email: vinicius@improveit.com.br
|
|
27
36
|
executables: []
|
|
@@ -34,6 +43,7 @@ extra_rdoc_files:
|
|
|
34
43
|
files:
|
|
35
44
|
- .document
|
|
36
45
|
- .gitignore
|
|
46
|
+
- CHANGELOG
|
|
37
47
|
- LICENSE
|
|
38
48
|
- README.rdoc
|
|
39
49
|
- Rakefile
|
|
@@ -55,18 +65,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
55
65
|
requirements:
|
|
56
66
|
- - ">="
|
|
57
67
|
- !ruby/object:Gem::Version
|
|
68
|
+
segments:
|
|
69
|
+
- 0
|
|
58
70
|
version: "0"
|
|
59
|
-
version:
|
|
60
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
72
|
requirements:
|
|
62
73
|
- - ">="
|
|
63
74
|
- !ruby/object:Gem::Version
|
|
75
|
+
segments:
|
|
76
|
+
- 0
|
|
64
77
|
version: "0"
|
|
65
|
-
version:
|
|
66
78
|
requirements: []
|
|
67
79
|
|
|
68
80
|
rubyforge_project:
|
|
69
|
-
rubygems_version: 1.3.
|
|
81
|
+
rubygems_version: 1.3.6
|
|
70
82
|
signing_key:
|
|
71
83
|
specification_version: 3
|
|
72
84
|
summary: This gem extends the Ruby class Array with a few useful methods.
|