epitools 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epitools}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["epitron"]
12
- s.date = %q{2010-09-28}
12
+ s.date = %q{2010-10-19}
13
13
  s.description = %q{Miscellaneous utility libraries to make my life easier.}
14
14
  s.email = %q{chris@ill-logic.com}
15
15
  s.extra_rdoc_files = [
@@ -61,16 +61,16 @@ Gem::Specification.new do |s|
61
61
  s.rubygems_version = %q{1.3.7}
62
62
  s.summary = %q{NOT UTILS... METILS!}
63
63
  s.test_files = [
64
- "spec/sys_spec.rb",
65
- "spec/permutations_spec.rb",
66
- "spec/rash_spec.rb",
67
- "spec/spec_helper.rb",
64
+ "spec/basetypes_spec.rb",
68
65
  "spec/browser_spec.rb",
69
66
  "spec/lcs_spec.rb",
70
- "spec/basetypes_spec.rb",
67
+ "spec/metaclass_spec.rb",
68
+ "spec/permutations_spec.rb",
69
+ "spec/rash_spec.rb",
71
70
  "spec/ratio_spec.rb",
72
- "spec/zopen_spec.rb",
73
- "spec/metaclass_spec.rb"
71
+ "spec/spec_helper.rb",
72
+ "spec/sys_spec.rb",
73
+ "spec/zopen_spec.rb"
74
74
  ]
75
75
 
76
76
  if s.respond_to? :specification_version then
@@ -92,6 +92,31 @@ class Array
92
92
  flatten.compact.uniq
93
93
  end
94
94
 
95
+ #
96
+ # Removes the elements from the array for which the block evaluates to true.
97
+ # In addition, return the removed elements.
98
+ #
99
+ # For example, if you wanted to split an array into evens and odds:
100
+ #
101
+ # nums = [1,2,3,4,5,6,7,8,9,10,11,12]
102
+ # even = nums.remove_if { |n| n.even? } # remove all even numbers from the "nums" array and return them
103
+ # odd = nums # "nums" now only contains odd numbers
104
+ #
105
+ def remove_if(&block)
106
+ removed = []
107
+
108
+ delete_if do |x|
109
+ if block.call(x)
110
+ removed << x
111
+ true
112
+ else
113
+ false
114
+ end
115
+ end
116
+
117
+ removed
118
+ end
119
+
95
120
  end
96
121
 
97
122
 
@@ -93,6 +93,15 @@ describe Array do
93
93
  [1,2,[3,4,[5],[],[nil,nil],[6]]].squash.should == [1,2,3,4,5,6]
94
94
  end
95
95
 
96
+ it "remove_ifs" do
97
+ nums = [1,2,3,4,5,6,7,8,9,10,11,12]
98
+ even = nums.remove_if { |n| n.even? } # remove all even numbers from the "nums" array and return them
99
+ odd = nums
100
+
101
+ even.should == [2,4,6,8,10,12]
102
+ odd.should == [1,3,5,7,9,11]
103
+ end
104
+
96
105
  end
97
106
 
98
107
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - epitron
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-28 00:00:00 -04:00
18
+ date: 2010-10-19 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -116,13 +116,13 @@ signing_key:
116
116
  specification_version: 3
117
117
  summary: NOT UTILS... METILS!
118
118
  test_files:
119
- - spec/sys_spec.rb
120
- - spec/permutations_spec.rb
121
- - spec/rash_spec.rb
122
- - spec/spec_helper.rb
119
+ - spec/basetypes_spec.rb
123
120
  - spec/browser_spec.rb
124
121
  - spec/lcs_spec.rb
125
- - spec/basetypes_spec.rb
122
+ - spec/metaclass_spec.rb
123
+ - spec/permutations_spec.rb
124
+ - spec/rash_spec.rb
126
125
  - spec/ratio_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/sys_spec.rb
127
128
  - spec/zopen_spec.rb
128
- - spec/metaclass_spec.rb