webget_ramp 1.7.1.7 → 1.7.1.8

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/lib/webget_ramp.rb CHANGED
@@ -69,7 +69,8 @@ Testing:
69
69
  * index_by: convert the array to a hash by mapping each ite to a key=>item pair.
70
70
  * join: forwards to self.to_a.join
71
71
  * map_id: returns the id of an Enumerable object; *requires* that the object respond to an 'id' message
72
- * map_to_a, map_to_f, map_to_i, map_to_s, map_to_sym : convert each object to a specific type by calling its respective method to_a, to_i, to_f, to_s, to_sym
72
+ * map_to_a, map_to_f, map_to_i, map_to_s, map_to_sym: convert each object to a specific type by calling its respective method to_a, to_i, to_f, to_s, to_sym
73
+ * map_with_index: for each item, yield to a block with the item and its incrementing index
73
74
  * nitems_until, select_until: returns the number of, or an array containing, the leading elements for which block is false or nil.
74
75
  * nitems_while, select_while: returns the number of items, or an array containing the leading elements, for which block is not false or nil.
75
76
  * nitems_with_index, select_with_index: calls block with two arguments, the item and its index, for each item in enum. Returns the number of, or an array containing, the leading elements for which block is not false or nil.
@@ -200,6 +201,7 @@ Extensions that help debug Ruby programs.
200
201
 
201
202
  == Changes
202
203
 
204
+ - 1.7.1.8 Add Enumerable#map_with_index
203
205
  - 1.7.1.6 Add ActiveRecord::SaveExtensions#save_false_then_reload!
204
206
  - 1.7.1.3 Add XML#strip_xxx
205
207
  - 1.7.1.2 Update gems: Gemcutter, Ruby 1.9.1, JRuby sqlite3
@@ -175,6 +175,22 @@ module Enumerable
175
175
  end
176
176
 
177
177
 
178
+ # Map each item and its index => a new output
179
+ #
180
+ # cf. Enumerable#map, Enumerable#each_with_index
181
+ #
182
+ # ==Example
183
+ #
184
+ # strings = ["a", "b", "c"]
185
+ # strings.map_with_index{|string,index| "#{string}#{index}"}
186
+ # => ["a0, "b1", "c3"]
187
+
188
+ def map_with_index
189
+ i=-1
190
+ map{|x| i+=1; yield(x,i)}
191
+ end
192
+
193
+
178
194
  ########################################################################
179
195
  #
180
196
  # select
@@ -85,6 +85,10 @@ class EnumerableTest < Test::Unit::TestCase
85
85
  assert_equal([:a,:b,:c],ITEMS.map_to_sym)
86
86
  end
87
87
 
88
+ def test_map_with_index
89
+ assert_equal(['a0','b1','c2'],ITEMS.map_with_index{|x,i| "#{x}#{i}"})
90
+ end
91
+
88
92
 
89
93
  ########################################################################
90
94
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webget_ramp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1.7
4
+ version: 1.7.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - WebGet
@@ -32,7 +32,7 @@ cert_chain:
32
32
  DXnLFY0cVuBnNDMOOFl8vk1qIcZjcTovhzgcixpG6Uk5qmUsKHRLQf4oQJx7TfLK
33
33
  -----END CERTIFICATE-----
34
34
 
35
- date: 2009-12-15 00:00:00 -08:00
35
+ date: 2010-02-09 00:00:00 -08:00
36
36
  default_executable:
37
37
  dependencies: []
38
38
 
metadata.gz.sig CHANGED
Binary file