kitchensink 0.1.1 → 0.2.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.
@@ -25,6 +25,24 @@ unless Array.method_defined? :product
25
25
  end
26
26
  end
27
27
 
28
+ unless Array.method_defined? :rand_index
29
+ class Array
30
+ # returns a random index from this array
31
+ def rand_index
32
+ rand(size)
33
+ end
34
+ end
35
+ end
36
+
37
+ unless Array.method_defined? :rand_value
38
+ class Array
39
+ # returns a random value from this array
40
+ def rand_value
41
+ self[rand(size)]
42
+ end
43
+ end
44
+ end
45
+
28
46
  unless Array.method_defined? :sum
29
47
  class Array
30
48
  # Adds all elements of an array together:
@@ -37,3 +55,25 @@ unless Array.method_defined? :sum
37
55
  end
38
56
  end
39
57
  end
58
+
59
+ unless (Array.method_defined?(:shuffle!) && Array.method_defined?(:shuffle))
60
+ class Array
61
+ # Returns an array with its elements shuffled. Uses algorithm from Ruby
62
+ # Cookbook 4.10
63
+ def shuffle!
64
+ each_index do |i|
65
+ j = rand(length-i) + i
66
+ self[j], self[i] = self[i], self[j]
67
+ end
68
+ end
69
+ end
70
+
71
+ class Array
72
+ # Returns an array with its elements shuffled. Uses algorithm from Ruby
73
+ # Cookbook 4.10
74
+ def shuffle
75
+ self.dup.shuffle!
76
+ end
77
+ end
78
+ end
79
+
@@ -26,3 +26,13 @@ unless Enumerable.method_defined? :rrest
26
26
  end
27
27
  end
28
28
 
29
+ unless Enumerable.method_defined? :shuffle
30
+ module Enumerable
31
+ # Returns an array with its elements shuffled. This is not a particularly
32
+ # efficient method because Enumerable doesn't provide random access. This
33
+ # is overridden with a more efficient method in Array.
34
+ def shuffle
35
+ self.sort_by { rand }
36
+ end
37
+ end
38
+ end
@@ -31,6 +31,35 @@ unless Hash.method_defined? :only
31
31
  end
32
32
  end
33
33
 
34
+ unless Hash.method_defined? :rand_key
35
+ class Hash
36
+ # returns a key chosen at from this array
37
+ def rand_key
38
+ keys[rand(keys.size)]
39
+ end
40
+ end
41
+ end
42
+
43
+ unless Hash.method_defined? :rand_pair
44
+ class Hash
45
+ # returns a key chosen at from this array
46
+ def rand_pair
47
+ k = rand_key
48
+ [k, self[k]]
49
+ end
50
+ end
51
+ end
52
+
53
+ unless Hash.method_defined? :rand_value
54
+ class Hash
55
+ # returns a key chosen at from this array
56
+ def rand_value
57
+ self[rand_key]
58
+ end
59
+ end
60
+ end
61
+
62
+
34
63
  unless Hash.method_defined? :with
35
64
  class Hash
36
65
  # Merge keys into a Hash.
@@ -1,11 +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
+ # 2008-03-18 dbrady: Removed for the nonce. There was a weird dependency on utility_belt here. If I remove utility_belt, this method breaks Rails' version of Symbol#to_proc
2
+ # unless Symbol.method_defined? :to_proc
3
+ # class Symbol
4
+ # # Convert a Symbol to proc.
5
+ # #
6
+ # # This is already in Ruby CVS, and should appear in Ruby 1.9
7
+ # def to_proc
8
+ # Proc.new { |obj, *args| obj.send(self, *args) }
9
+ # end
10
+ # end
11
+ # end
@@ -1,7 +1,7 @@
1
1
  module Kitchensink #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -1,5 +1,8 @@
1
1
  desc 'Release the website and new gem version'
2
- task :deploy => [:check_version, :website, :release] do
2
+ task :deploy => [:check_version, :website, :release, :suggest_tag] do
3
+ end
4
+
5
+ task :suggest_tag do
3
6
  puts "Remember to create SVN tag:"
4
7
  puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
8
  "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
@@ -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.1.1</a>
36
+ <a href="http://rubyforge.org/projects/kitchensink" class="numbers">0.2.1</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;kitchensink&#8217;</h1>
39
39
 
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.1.1
4
+ version: 0.2.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-18 00:00:00 -06:00
12
+ date: 2008-03-25 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15