rext 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,15 @@
1
1
 
2
+ 0.5.0 / 2009-11-12
3
+ ==================
4
+
5
+ * Added Enumerable#take
6
+ * Added Enumerable#drop
7
+
8
+ 0.4.1 / 2009-11-10
9
+ ==================
10
+
11
+ * Fix Hash#to_query support both Rack's #build_query and #build_nested_query
12
+
2
13
  0.4.0 / 2009-11-10
3
14
  ==================
4
15
 
@@ -101,6 +101,8 @@ Below are the methods currently provided by Rext.
101
101
  - group_by
102
102
  - includes_all?
103
103
  - every
104
+ - take
105
+ - drop
104
106
 
105
107
  * Symbol
106
108
  - to_proc
@@ -4,17 +4,17 @@ require 'enumerator'
4
4
  class Array
5
5
 
6
6
  ##
7
- # Return array of elements after +position+.
7
+ # Return array of elements after _index_.
8
8
 
9
- def from position
10
- self[position..-1]
9
+ def from index
10
+ self[index..-1]
11
11
  end
12
12
 
13
13
  ##
14
- # Return array of elements up to +position+.
14
+ # Return array of elements up to _index_.
15
15
 
16
- def to position
17
- self[0..position]
16
+ def to index
17
+ self[0..index]
18
18
  end
19
19
 
20
20
  ##
@@ -85,4 +85,45 @@ module Enumerable
85
85
  args.all? { |arg| include? arg }
86
86
  end
87
87
 
88
+ ##
89
+ # Drop _n_ elements, returning the others.
90
+ # You may also pass a _block_ which acts as
91
+ # Enumerable#reject.
92
+ #
93
+ # === Examples
94
+ #
95
+ # [1,2,3,4].drop # => [2,3,4]
96
+ # [1,2,3,4].drop(2) # => [3,4]
97
+ # [1,2,3,4].drop(-2) # => [1,2]
98
+ # [1,2,3,4,5].drop { |n| n < 4 } # => [4,5]
99
+ #
100
+
101
+ def drop n = 1, &block
102
+ case
103
+ when block ; reject &block
104
+ when n < 0 ; self[0...n]
105
+ else self[n..-1]
106
+ end
107
+ end
108
+
109
+ ##
110
+ # Take _n_ elements, or pass a _block_ which
111
+ # acts as Enumerable#select.
112
+ #
113
+ # === Examples
114
+ #
115
+ # [1,2,3,4].take # => [1]
116
+ # [1,2,3,4].take(2) # => [1,2]
117
+ # [1,2,3,4].take(-2) # => [3,4]
118
+ # [1,2,3,4].take { |n| == 1 } # => [1]
119
+ #
120
+
121
+ def take n = 1, &block
122
+ case
123
+ when block ; select &block
124
+ when n < 0 ; self[n..-1]
125
+ else self[0...n]
126
+ end
127
+ end
128
+
88
129
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rext
3
- VERSION = '0.4.1'
3
+ VERSION = '0.5.0'
4
4
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rext}
5
- s.version = "0.4.1"
5
+ s.version = "0.5.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["TJ Holowaychuk"]
9
- s.date = %q{2009-11-10}
9
+ s.date = %q{2009-11-12}
10
10
  s.description = %q{Ruby extensions}
11
11
  s.email = %q{tj@vision-media.ca}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/rext.rb", "lib/rext/all.rb", "lib/rext/array.rb", "lib/rext/array/helpers.rb", "lib/rext/date.rb", "lib/rext/date/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/hash.rb", "lib/rext/hash/helpers.rb", "lib/rext/integer.rb", "lib/rext/integer/helpers.rb", "lib/rext/module.rb", "lib/rext/module/helpers.rb", "lib/rext/numeric.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/object.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/proc.rb", "lib/rext/proc/helpers.rb", "lib/rext/process.rb", "lib/rext/process/helpers.rb", "lib/rext/string.rb", "lib/rext/string/encode.rb", "lib/rext/string/helpers.rb", "lib/rext/symbol.rb", "lib/rext/symbol/helpers.rb", "lib/rext/time.rb", "lib/rext/time/helpers.rb", "lib/rext/version.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
@@ -15,6 +15,43 @@ describe Enumerable do
15
15
  end
16
16
  end
17
17
 
18
+ describe "#drop" do
19
+ it "should drop the first item" do
20
+ [1,2,3].drop.should == [2,3]
21
+ end
22
+
23
+ it "should drop the first n items" do
24
+ [1,2,3,4].drop(2).should == [3,4]
25
+ end
26
+
27
+ it "should drop the last n items" do
28
+ [1,2,3,4].drop(-2).should == [1,2]
29
+ end
30
+
31
+ it "should drop using a block" do
32
+ [1,2,3,4,5].drop { |n| n < 4 }.should == [4,5]
33
+ end
34
+ end
35
+
36
+ describe "#take" do
37
+ it "should return the first item" do
38
+ [1,2,3].take.should == [1]
39
+ end
40
+
41
+ it "should return the first n items" do
42
+ [1,2,3].take(2).should == [1,2]
43
+ end
44
+
45
+ it "should return the last n items" do
46
+ [1,2,3,4].take(-3).should == [2,3,4]
47
+ [1,2,3,4].take(-1).should == [4]
48
+ end
49
+
50
+ it "should return items using a block" do
51
+ [1,2,3].take { |n| n == 1 }.should == [1]
52
+ end
53
+ end
54
+
18
55
  describe "#group_by" do
19
56
  before :each do
20
57
  @enum = 'foo', :bar, 1, 2, 3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-10 00:00:00 -08:00
12
+ date: 2009-11-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15