kitchensink 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +2 -0
- data/lib/kitchensink/patches/enumerable.rb +20 -4
- data/lib/kitchensink/version.rb +1 -1
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- data/spec/patches/enumerable_spec.rb +47 -0
- data/spec/spec_helper.rb +29 -0
- data/website/index.html +2 -5
- data/website/index.txt +0 -2
- metadata +5 -3
data/Manifest.txt
CHANGED
@@ -2,7 +2,11 @@ unless Enumerable.method_defined? :rest
|
|
2
2
|
module Enumerable
|
3
3
|
# Returns all elements after the first.
|
4
4
|
def rest
|
5
|
-
self[
|
5
|
+
if self.respond_to? :[]
|
6
|
+
self[1..-1]
|
7
|
+
else
|
8
|
+
self.to_a[1..-1]
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
12
|
end
|
@@ -21,18 +25,30 @@ unless Enumerable.method_defined? :rrest
|
|
21
25
|
# means, and that with a little context the reader could determine the
|
22
26
|
# meaning correctly almost all every time.
|
23
27
|
def rrest
|
24
|
-
self[
|
28
|
+
if self.respond_to? :[]
|
29
|
+
self[0..-2]
|
30
|
+
else
|
31
|
+
self.to_a[0..-2]
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
28
36
|
|
29
|
-
unless Enumerable.method_defined?
|
37
|
+
unless Enumerable.method_defined?(:shuffle)
|
30
38
|
module Enumerable
|
31
39
|
# Returns an array with its elements shuffled. This is not a particularly
|
32
40
|
# efficient method because Enumerable doesn't provide random access. This
|
33
41
|
# is overridden with a more efficient method in Array.
|
42
|
+
#
|
43
|
+
# Note that there is no corresponding shuffle! method because shuffle
|
44
|
+
# returns an Array. If it ever makes sense to replace an IO or a Socket or
|
45
|
+
# a Struct with an Array, it probably also makes sense for you to have to
|
46
|
+
# write that method directly in the child class. The trivial
|
47
|
+
# implementation is straightforward: +self.replace(self.shuffle)+, but as
|
48
|
+
# was the case with Array, there is probably a more efficient
|
49
|
+
# implementation available.
|
34
50
|
def shuffle
|
35
|
-
|
51
|
+
sort_by { rand }
|
36
52
|
end
|
37
53
|
end
|
38
54
|
end
|
data/lib/kitchensink/version.rb
CHANGED
data/script/destroy
CHANGED
File without changes
|
data/script/generate
CHANGED
File without changes
|
data/script/txt2html
CHANGED
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe "Enumerable" do
|
4
|
+
describe "shuffle" do
|
5
|
+
it "should mix Hash key/values into an array of pairs" do
|
6
|
+
h = {:a=>9, :b=>"foo", :c=>42}
|
7
|
+
h.should respond_to(:shuffle)
|
8
|
+
s = h.shuffle
|
9
|
+
s.should be_kind_of(Array)
|
10
|
+
s.size.should == h.size
|
11
|
+
s.each do |k,v|
|
12
|
+
h.should be_key(k)
|
13
|
+
h[k].should == v
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should work with unindexable Enumerables by converting them to arrays" do
|
18
|
+
s = (3..6).shuffle
|
19
|
+
s.size.should == 4
|
20
|
+
(3..6).each do |i|
|
21
|
+
s.should include(i)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "rest" do
|
27
|
+
it "should return all but the head" do
|
28
|
+
a = (1..10).to_a
|
29
|
+
a.rest.should == (2..10).to_a
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should work with unindexable Enumerables by converting them to arrays" do
|
33
|
+
(1..10).rest.should == (2..10).to_a
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "rrest" do
|
38
|
+
it "should return all but the tail" do
|
39
|
+
a = (1..10).to_a
|
40
|
+
a.rrest.should == (1..9).to_a
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should work with unindexable Enumerables by converting them to arrays" do
|
44
|
+
(1..10).rrest.should == (1..9).to_a
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
require 'kitchensink'
|
4
|
+
|
5
|
+
# class RespondTo
|
6
|
+
# def initialize(expected)
|
7
|
+
# @expected = expected
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# def matches?(actual)
|
11
|
+
# @actual = actual
|
12
|
+
# # Satisfy expectation here. Return false or raise an error if it's not met.
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# true
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# def failure_message
|
19
|
+
# "expected #{@actual.inspect} to respond_to #{@expected.inspect}, but it didn't"
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def negative_failure_message
|
23
|
+
# "expected #{@actual.inspect} not to respond_to #{@expected.inspect}, but it did"
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# def respond_to(expected)
|
28
|
+
# RespondTo.new(expected)
|
29
|
+
# end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>kitchensink</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/kitchensink"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/kitchensink" class="numbers">0.2.
|
36
|
+
<a href="http://rubyforge.org/projects/kitchensink" class="numbers">0.2.2</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘kitchensink’</h1>
|
39
39
|
|
@@ -59,9 +59,6 @@
|
|
59
59
|
<p><a href="http://groups.google.com/group/kitchensink">http://groups.google.com/group/kitchensink</a></p>
|
60
60
|
|
61
61
|
|
62
|
-
<p><span class="caps">TODO</span> – create Google Group – kitchensink</p>
|
63
|
-
|
64
|
-
|
65
62
|
<h2>How to submit patches</h2>
|
66
63
|
|
67
64
|
|
@@ -82,7 +79,7 @@
|
|
82
79
|
|
83
80
|
<p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/kitchensink">forum</a></p>
|
84
81
|
<p class="coda">
|
85
|
-
<a href="FIXME email">FIXME full name</a>,
|
82
|
+
<a href="FIXME email">FIXME full name</a>, 25th March 2008<br>
|
86
83
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
87
84
|
</p>
|
88
85
|
</div>
|
data/website/index.txt
CHANGED
@@ -21,8 +21,6 @@ h2. Forum
|
|
21
21
|
|
22
22
|
"http://groups.google.com/group/kitchensink":http://groups.google.com/group/kitchensink
|
23
23
|
|
24
|
-
TODO - create Google Group - kitchensink
|
25
|
-
|
26
24
|
h2. How to submit patches
|
27
25
|
|
28
26
|
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchensink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FIXME full name
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-04-24 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -47,6 +47,8 @@ files:
|
|
47
47
|
- script/generate
|
48
48
|
- script/txt2html
|
49
49
|
- setup.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
- spec/patches/enumerable_spec.rb
|
50
52
|
- tasks/deployment.rake
|
51
53
|
- tasks/environment.rake
|
52
54
|
- tasks/website.rake
|
@@ -80,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
82
|
requirements: []
|
81
83
|
|
82
84
|
rubyforge_project: kitchensink
|
83
|
-
rubygems_version: 1.0
|
85
|
+
rubygems_version: 1.1.0
|
84
86
|
signing_key:
|
85
87
|
specification_version: 2
|
86
88
|
summary: description of gem
|