kitchensink 0.0.1 → 0.1.1

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.
@@ -7,6 +7,12 @@ config/hoe.rb
7
7
  config/requirements.rb
8
8
  lib/kitchensink.rb
9
9
  lib/kitchensink/version.rb
10
+ lib/kitchensink/patches/array.rb
11
+ lib/kitchensink/patches/class.rb
12
+ lib/kitchensink/patches/enumerable.rb
13
+ lib/kitchensink/patches/hash.rb
14
+ lib/kitchensink/patches/object.rb
15
+ lib/kitchensink/patches/symbol.rb
10
16
  log/debug.log
11
17
  script/destroy
12
18
  script/generate
@@ -1,200 +1 @@
1
- $:.unshift File.dirname(__FILE__)
2
-
3
- unless Enumerable.method_defined? :rest
4
- module Enumerable
5
- # Returns all elements after the first.
6
- def rest
7
- self[1..-1]
8
- end
9
- end
10
- end
11
-
12
- unless Enumerable.method_defined? :rrest
13
- module Enumerable
14
- # Returns a new collection containing all elements except for the last
15
- #--
16
- # This has a very PHPesque name and needs a better one. (PHP has an idiom
17
- # where array methods that work in one direction can be reversed by
18
- # prepending r to them. See sort=>rsort, ksort=>krsort, and asort=>arsort.
19
- # Problem is, what's a good word meaning "everything but the last"? I
20
- # briefly toyed with "lizard" since it's the Enumeration "with the tail
21
- # cut off" but that's not very intuitive to somebody looking at the method
22
- # for the first time. I need a word that suggests to the reader what it
23
- # means, and that with a little context the reader could determine the
24
- # meaning correctly almost all every time.
25
- def rrest
26
- self[0..-2]
27
- end
28
- end
29
- end
30
-
31
- unless Array.method_defined? :sum
32
- class Array
33
- # Adds all elements of an array together:
34
- # * [1,2,3].sum => 6
35
- # * [1.0, 2.0, 3.0].sum => 6.0
36
- # * %w{a b c}.sum => "abc"
37
- # * [Vector[1,0,0], Vector[0,2,0], Vector[0,0,3]].sum => Vector[1,2,3]
38
- def sum
39
- inject {|sum,element| sum+element}
40
- end
41
- end
42
- end
43
-
44
- unless Array.method_defined? :product
45
- class Array
46
- # Multiplies all elements of an array together:
47
- # * [2,3,4].product => 24
48
- # * [2.0, 3.0, 4.0].product => 24.0
49
- # * ["NO", 3, 2].product => "NONONONONONO"
50
- def product
51
- inject {|product,element| product*element}
52
- end
53
- end
54
- end
55
-
56
- unless Array.method_defined? :hash_by
57
- class Array
58
- # Construct a hash of objects, keyed by some object attribute.
59
- #
60
- # Original idea and code by Brian Dainton. Taken from his blog, The Budding Rubyist.
61
- # http://buddingrubyist.wordpress.com/2008/02/05/why-i-like-to-inject/
62
- def hash_by(attribute)
63
- inject({}) do |results, obj|
64
- results[obj.send(attribute)] = obj
65
- results
66
- end
67
- end
68
- end
69
- end
70
-
71
-
72
- unless Object.respond_to? :class_method
73
- class Object
74
- # Returns an +UnboundMethod+ representing a given class method in a class.
75
- #
76
- # See Also: instance_method
77
- #
78
- # Examples:
79
- # sc = String.class_method(:superclass)
80
- # sc.bind(String).call()
81
- # => Object
82
- #--
83
- # Note that here we use the "class << self; self; end.send" trick, which
84
- # gives us access to the singleton class rather than the class itself.
85
- # Setting instance methods here causes the subclass to receive class
86
- # methods. Yay!
87
- def self.class_method(name)
88
- class << self; self; end.send :instance_method, name
89
- end
90
- end
91
- end
92
-
93
- unless Object.respond_to? :remove_class_method
94
- class Object
95
- # Removes a class method.
96
- def self.remove_class_method(name)
97
- class << self; self; end.send :remove_method, name
98
- end
99
- end
100
- end
101
-
102
- unless Object.respond_to? :define_class_method
103
- class Object
104
- # Works like define_method, only creates a class method.
105
- # * <tt>define_class_method(symbol, method)</tt> => new_method
106
- # * <tt>define_class_method(symbol) {block}</tt> => proc
107
- #
108
- # Examples:
109
- # String.define_class_method :get_parent_class, String.class_method(:superclass)
110
- # String.define_class_method :make_runon do |str, num|
111
- # String.new(str) * num
112
- # end
113
- # String.make_runon "abc", 3
114
- # => "abcabcabc"
115
- def self.define_class_method(name, method=nil, &block)
116
- if method
117
- class << self; self; end.send :define_method, name, method
118
- else
119
- class << self; self; end.send :define_method, name, &block
120
- end
121
- end
122
- end
123
- end
124
-
125
- unless Object.method_defined? :included_in?
126
- class Object
127
- # True if a collection includes this object.
128
- #
129
- # Note: I wrote this because
130
- # sometimes <tt>collection.include?(object)</tt> violates left-to-right reading
131
- # order, such as when +object+ is more important than the +collection+.
132
- def included_in?(collection)
133
- collection.include? self
134
- end
135
- end
136
- end
137
-
138
- unless Symbol.method_defined? :to_proc
139
- class Symbol
140
- # Convert a Symbol to proc.
141
- #
142
- # This is already in Ruby CVS, and should appear in Ruby 1.9
143
- def to_proc
144
- Proc.new { |obj, *args| obj.send(self, *args) }
145
- end
146
- end
147
- end
148
-
149
- unless Hash.method_defined? :except
150
- class Hash
151
- # Filter keys out of a Hash.
152
- #
153
- # >> {:a=>1, :b=>2, :c=>3}.except(:a)
154
- # => {:b=>2, :c=>3}
155
- #
156
- # Source:
157
- # * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
158
- # * Neil Rahilly
159
- # * Peepcode episode 11. Geoffrey Grosenbach alludes to this being a
160
- # common idiom among rSpec coders.
161
- def except(*keys)
162
- self.reject { |k,v| keys.include?(k || k.to_sym) }
163
- end
164
- end
165
- end
166
-
167
- unless Hash.method_defined? :only
168
- class Hash
169
- # Returns a hash with only the pairs identified by +keys+
170
- #
171
- # Source:
172
- # * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
173
- # * Neil Rahilly
174
- # * Peepcode episode 11. Geoffrey Grosenbach alludes to this being a
175
- # common idiom among rSpec coders.
176
- def only(*keys)
177
- self.reject { |k,v| !keys.include?(k || k.to_sym) }
178
- end
179
- end
180
- end
181
-
182
- unless Hash.method_defined? :with
183
- class Hash
184
- # Merge keys into a Hash.
185
- #
186
- # >> {:a=>1, :b=>2, :c=>3}.with({:a=>4,:b=>5})
187
- # => {:a=>4, :b=>5, :c=>3}
188
- #
189
- # Source:
190
- # * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
191
- # * Neil Rahilly
192
- # * Peepcode episode 11. Geoffrey Grosenbach alludes to this being a
193
- # common idiom among rSpec coders.
194
- #
195
- # Known Issue: This method conflicts with utility_belt's with statement.
196
- def with(overrides = {})
197
- self.merge overrides
198
- end
199
- end
200
- end
1
+ Dir.glob(File.join(File.dirname(__FILE__), "kitchensink", "patches", "*.rb")).each {|f| require f}
@@ -0,0 +1,39 @@
1
+ unless Array.method_defined? :hash_by
2
+ class Array
3
+ # Construct a hash of objects, keyed by some object attribute.
4
+ #
5
+ # Original idea and code by Brian Dainton. Taken from his blog, The Budding Rubyist.
6
+ # http://buddingrubyist.wordpress.com/2008/02/05/why-i-like-to-inject/
7
+ def hash_by(attribute)
8
+ inject({}) do |results, obj|
9
+ results[obj.send(attribute)] = obj
10
+ results
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ unless Array.method_defined? :product
17
+ class Array
18
+ # Multiplies all elements of an array together:
19
+ # * [2,3,4].product => 24
20
+ # * [2.0, 3.0, 4.0].product => 24.0
21
+ # * ["NO", 3, 2].product => "NONONONONONO"
22
+ def product
23
+ inject {|product,element| product*element}
24
+ end
25
+ end
26
+ end
27
+
28
+ unless Array.method_defined? :sum
29
+ class Array
30
+ # Adds all elements of an array together:
31
+ # * [1,2,3].sum => 6
32
+ # * [1.0, 2.0, 3.0].sum => 6.0
33
+ # * %w{a b c}.sum => "abc"
34
+ # * [Vector[1,0,0], Vector[0,2,0], Vector[0,0,3]].sum => Vector[1,2,3]
35
+ def sum
36
+ inject {|sum,element| sum+element}
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ unless Class.respond_to? :descendants
2
+ class Class
3
+ # Return a list of all classes currently known to inherit from this class, directly or indirectly.
4
+ #
5
+ # NOTE that this only checks objects currently in memory. For instance, if you start a Rails console and check the descendants of ActiveRecord::Base, you'll only find those objects that have been dynamically loaded.
6
+ def descendants
7
+ dd = []
8
+ ObjectSpace::each_object(Class) do |c|
9
+ dd << c if c.ancestors.include?(self)
10
+ end
11
+ dd
12
+ end
13
+ end
14
+ end
15
+
16
+ unless Class.respond_to? :immediate_descendants
17
+ class Class
18
+ # Return a list of all classes currently known to directly inherit from this class.
19
+ #
20
+ # NOTE that this only checks objects currently in memory. For instance, if you start a Rails console and check the descendants of ActiveRecord::Base, you'll only find those objects that have been dynamically loaded.
21
+ def immediate_descendants
22
+ dd = []
23
+ ObjectSpace::each_object(Class) do |c|
24
+ dd << c if c.ancestors.size > 1 && c.ancestors[1] == self
25
+ end
26
+ dd
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ unless Enumerable.method_defined? :rest
2
+ module Enumerable
3
+ # Returns all elements after the first.
4
+ def rest
5
+ self[1..-1]
6
+ end
7
+ end
8
+ end
9
+
10
+ unless Enumerable.method_defined? :rrest
11
+ module Enumerable
12
+ # Returns a new collection containing all elements except for the last
13
+ #--
14
+ # This has a very PHPesque name and needs a better one. (PHP has an idiom
15
+ # where array methods that work in one direction can be reversed by
16
+ # prepending r to them. See sort=>rsort, ksort=>krsort, and asort=>arsort.
17
+ # Problem is, what's a good word meaning "everything but the last"? I
18
+ # briefly toyed with "lizard" since it's the Enumeration "with the tail
19
+ # cut off" but that's not very intuitive to somebody looking at the method
20
+ # for the first time. I need a word that suggests to the reader what it
21
+ # means, and that with a little context the reader could determine the
22
+ # meaning correctly almost all every time.
23
+ def rrest
24
+ self[0..-2]
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,53 @@
1
+ unless Hash.method_defined? :except
2
+ class Hash
3
+ # Filter keys out of a Hash.
4
+ #
5
+ # >> {:a=>1, :b=>2, :c=>3}.except(:a)
6
+ # => {:b=>2, :c=>3}
7
+ #
8
+ # Source:
9
+ # * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
10
+ # * Neil Rahilly
11
+ # * Peepcode episode 11. Geoffrey Grosenbach alludes to this being a
12
+ # common idiom among rSpec coders.
13
+ def except(*keys)
14
+ self.reject { |k,v| keys.include?(k || k.to_sym) }
15
+ end
16
+ end
17
+ end
18
+
19
+ unless Hash.method_defined? :only
20
+ class Hash
21
+ # Returns a hash with only the pairs identified by +keys+
22
+ #
23
+ # Source:
24
+ # * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
25
+ # * Neil Rahilly
26
+ # * Peepcode episode 11. Geoffrey Grosenbach alludes to this being a
27
+ # common idiom among rSpec coders.
28
+ def only(*keys)
29
+ self.reject { |k,v| !keys.include?(k || k.to_sym) }
30
+ end
31
+ end
32
+ end
33
+
34
+ unless Hash.method_defined? :with
35
+ class Hash
36
+ # Merge keys into a Hash.
37
+ #
38
+ # >> {:a=>1, :b=>2, :c=>3}.with({:a=>4,:b=>5})
39
+ # => {:a=>4, :b=>5, :c=>3}
40
+ #
41
+ # Source:
42
+ # * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
43
+ # * Neil Rahilly
44
+ # * Peepcode episode 11. Geoffrey Grosenbach alludes to this being a
45
+ # common idiom among rSpec coders.
46
+ #
47
+ # Known Issue: This method conflicts with utility_belt's with statement.
48
+ def with(overrides = {})
49
+ self.merge overrides
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,66 @@
1
+ unless Object.respond_to? :class_method
2
+ class Object
3
+ # Returns an +UnboundMethod+ representing a given class method in a class.
4
+ #
5
+ # See Also: instance_method
6
+ #
7
+ # Examples:
8
+ # sc = String.class_method(:superclass)
9
+ # sc.bind(String).call()
10
+ # => Object
11
+ #--
12
+ # Note that here we use the "class << self; self; end.send" trick, which
13
+ # gives us access to the singleton class rather than the class itself.
14
+ # Setting instance methods here causes the subclass to receive class
15
+ # methods. Yay!
16
+ def self.class_method(name)
17
+ class << self; self; end.send :instance_method, name
18
+ end
19
+ end
20
+ end
21
+
22
+ unless Object.respond_to? :define_class_method
23
+ class Object
24
+ # Works like define_method, only creates a class method.
25
+ # * <tt>define_class_method(symbol, method)</tt> => new_method
26
+ # * <tt>define_class_method(symbol) {block}</tt> => proc
27
+ #
28
+ # Examples:
29
+ # String.define_class_method :get_parent_class, String.class_method(:superclass)
30
+ # String.define_class_method :make_runon do |str, num|
31
+ # String.new(str) * num
32
+ # end
33
+ # String.make_runon "abc", 3
34
+ # => "abcabcabc"
35
+ def self.define_class_method(name, method=nil, &block)
36
+ if method
37
+ class << self; self; end.send :define_method, name, method
38
+ else
39
+ class << self; self; end.send :define_method, name, &block
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ unless Object.method_defined? :included_in?
46
+ class Object
47
+ # True if a collection includes this object.
48
+ #
49
+ # Note: I wrote this because
50
+ # sometimes <tt>collection.include?(object)</tt> violates left-to-right reading
51
+ # order, such as when +object+ is more important than the +collection+.
52
+ def included_in?(collection)
53
+ collection.include? self
54
+ end
55
+ end
56
+ end
57
+
58
+ unless Object.respond_to? :remove_class_method
59
+ class Object
60
+ # Removes a class method.
61
+ def self.remove_class_method(name)
62
+ class << self; self; end.send :remove_method, name
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,11 @@
1
+ unless Symbol.method_defined? :to_proc
2
+ class Symbol
3
+ # Convert a Symbol to proc.
4
+ #
5
+ # This is already in Ruby CVS, and should appear in Ruby 1.9
6
+ def to_proc
7
+ Proc.new { |obj, *args| obj.send(self, *args) }
8
+ end
9
+ end
10
+ end
11
+
@@ -1,7 +1,7 @@
1
1
  module Kitchensink #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
4
+ MINOR = 1
5
5
  TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -31,4 +31,4 @@ namespace :manifest do
31
31
  task :refresh do
32
32
  `rake check_manifest | patch -p0 > Manifest.txt`
33
33
  end
34
- end
34
+ end
@@ -1,11 +1,93 @@
1
- <html>
2
- <head>
3
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
4
- <title>kitchensink</title>
5
-
6
- </head>
7
- <body id="body">
8
- <p>This page has not yet been created for RubyGem <code>kitchensink</code></p>
9
- <p>To the developer: To generate it, update website/index.txt and run the rake task <code>website</code> to generate this <code>index.html</code> file.</p>
10
- </body>
11
- </html>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ kitchensink
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>kitchensink</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/kitchensink"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/kitchensink" class="numbers">0.1.1</a>
37
+ </div>
38
+ <h1>&#x2192; &#8216;kitchensink&#8217;</h1>
39
+
40
+
41
+ <h2>What</h2>
42
+
43
+
44
+ <h2>Installing</h2>
45
+
46
+
47
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">kitchensink</span></pre></p>
48
+
49
+
50
+ <h2>The basics</h2>
51
+
52
+
53
+ <h2>Demonstration of usage</h2>
54
+
55
+
56
+ <h2>Forum</h2>
57
+
58
+
59
+ <p><a href="http://groups.google.com/group/kitchensink">http://groups.google.com/group/kitchensink</a></p>
60
+
61
+
62
+ <p><span class="caps">TODO</span> &#8211; create Google Group &#8211; kitchensink</p>
63
+
64
+
65
+ <h2>How to submit patches</h2>
66
+
67
+
68
+ <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
69
+
70
+
71
+ <p>The trunk repository is <code>svn://rubyforge.org/var/svn/kitchensink/trunk</code> for anonymous access.</p>
72
+
73
+
74
+ <h2>License</h2>
75
+
76
+
77
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
78
+
79
+
80
+ <h2>Contact</h2>
81
+
82
+
83
+ <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
+ <p class="coda">
85
+ <a href="FIXME email">FIXME full name</a>, 1st March 2008<br>
86
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
87
+ </p>
88
+ </div>
89
+
90
+ <!-- insert site tracking codes here, like Google Urchin -->
91
+
92
+ </body>
93
+ </html>
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.0.1
4
+ version: 0.1.1
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-03-01 00:00:00 -07:00
12
+ date: 2008-03-18 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -36,6 +36,12 @@ files:
36
36
  - config/requirements.rb
37
37
  - lib/kitchensink.rb
38
38
  - lib/kitchensink/version.rb
39
+ - lib/kitchensink/patches/array.rb
40
+ - lib/kitchensink/patches/class.rb
41
+ - lib/kitchensink/patches/enumerable.rb
42
+ - lib/kitchensink/patches/hash.rb
43
+ - lib/kitchensink/patches/object.rb
44
+ - lib/kitchensink/patches/symbol.rb
39
45
  - log/debug.log
40
46
  - script/destroy
41
47
  - script/generate