mack_ruby_core_extensions 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,3 +1,20 @@
1
- README
2
- ========================================================================
3
- mack_ruby_core_extensions
1
+ =Hello, and welcome to the Mack Ruby Core Extensions!
2
+
3
+ These are a collection of extensions to the Ruby core libraries meant to help with the development of Mack and Mack applications. Please enjoy.
4
+
5
+ ==Contact
6
+ Please mail bugs, suggestions and patches to <bugs@mackframework.com>.
7
+
8
+ On the web at: http://www.mackframework.com
9
+
10
+ ==License and Copyright
11
+ Copyright (C) 2008 Mark Bates, http://www.mackframework.com
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18
+
19
+ ==Other documentation:
20
+ * Mack[http://api.mackframework.com]
@@ -134,8 +134,8 @@
134
134
  This will give you a <a href="Array.html#M000016">count</a>, as a <a
135
135
  href="Hash.html">Hash</a>, of all the values in the <a
136
136
  href="Array.html">Array</a>. %w{spam spam eggs ham eggs spam}.<a
137
- href="Array.html#M000016">count</a> # =&gt; {&quot;eggs&quot;=&gt;2,
138
- &quot;ham&quot;=&gt;1, &quot;spam&quot;=&gt;3}
137
+ href="Array.html#M000016">count</a> # =&gt; {&quot;eggs&quot; =&gt; 2,
138
+ &quot;ham&quot; =&gt; 1, &quot;spam&quot; =&gt; 3}
139
139
  </p>
140
140
  <p><a class="source-toggle" href="#"
141
141
  onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
@@ -173,7 +173,7 @@ This allows you to delete an array of values from another array.
173
173
  <pre>
174
174
  <span class="ruby-comment cmt"># File lib/extensions/array.rb, line 37</span>
175
175
  37: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_from_array</span>(<span class="ruby-identifier">args</span>)
176
- 38: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">collect</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">x</span>)}.<span class="ruby-identifier">compact</span>
176
+ 38: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">collect</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> <span class="ruby-keyword kw">unless</span> [<span class="ruby-identifier">args</span>].<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">x</span>)}.<span class="ruby-identifier">compact</span>
177
177
  39: <span class="ruby-keyword kw">end</span>
178
178
  </pre>
179
179
  </div>
@@ -220,8 +220,8 @@ but will permantly replace the existing array.
220
220
  <p>
221
221
  This will <a href="Array.html#M000017">invert</a> the index and the values
222
222
  and return a <a href="Hash.html">Hash</a> of the results. %w{red yellow
223
- orange}.<a href="Array.html#M000017">invert</a> # =&gt;
224
- {&quot;red&quot;=&gt;0, &quot;orange&quot;=&gt;2, &quot;yellow&quot;=&gt;1}
223
+ orange}.<a href="Array.html#M000017">invert</a> # =&gt; {&quot;red&quot;
224
+ =&gt; 0, &quot;orange&quot; =&gt; 2, &quot;yellow&quot; =&gt; 1}
225
225
  </p>
226
226
  <p><a class="source-toggle" href="#"
227
227
  onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Tue, 25 Mar 2008 16:58:54 -0400
1
+ Tue, 25 Mar 2008 17:19:35 -0400
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Mar 25 14:51:49 -0400 2008</td>
59
+ <td>Tue Mar 25 17:19:14 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -69,13 +69,54 @@
69
69
  <div id="contextContent">
70
70
 
71
71
  <div id="description">
72
- <p>
73
- README
72
+ <h1>Hello, and welcome to the <a href="../classes/Mack.html">Mack</a> Ruby Core Extensions!</h1>
73
+ <p>
74
+ These are a collection of extensions to the Ruby core libraries meant to
75
+ help with the development of <a href="../classes/Mack.html">Mack</a> and <a
76
+ href="../classes/Mack.html">Mack</a> applications. Please enjoy.
77
+ </p>
78
+ <h2>Contact</h2>
79
+ <p>
80
+ Please mail bugs, suggestions and patches to
81
+ &lt;bugs@mackframework.com&gt;.
82
+ </p>
83
+ <p>
84
+ On the web at: <a
85
+ href="http://www.mackframework.com">www.mackframework.com</a>
86
+ </p>
87
+ <h2>License and Copyright</h2>
88
+ <p>
89
+ Copyright (C) 2008 Mark Bates, <a
90
+ href="http://www.mackframework.com">www.mackframework.com</a>
91
+ </p>
92
+ <p>
93
+ Permission is hereby granted, free of charge, to any person obtaining a
94
+ copy of this software and associated documentation files (the
95
+ &quot;Software&quot;), to deal in the Software without restriction,
96
+ including without limitation the rights to use, copy, modify, merge,
97
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
98
+ permit persons to whom the Software is furnished to do so, subject to the
99
+ following conditions:
74
100
  </p>
75
- <h6>==================================================================</h6>
76
101
  <p>
77
- mack_ruby_core_extensions
102
+ The above copyright notice and this permission notice shall be included in
103
+ all copies or substantial portions of the Software.
78
104
  </p>
105
+ <p>
106
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
107
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
109
+ NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
110
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
111
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
112
+ DEALINGS IN THE SOFTWARE.
113
+ </p>
114
+ <h2>Other documentation:</h2>
115
+ <ul>
116
+ <li><a href="http://api.mackframework.com">Mack</a>
117
+
118
+ </li>
119
+ </ul>
79
120
 
80
121
  </div>
81
122
 
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Mar 25 15:41:02 -0400 2008</td>
59
+ <td>Tue Mar 25 17:16:02 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -35,7 +35,7 @@ class Array
35
35
  # This allows you to delete an array of values from another array.
36
36
  # [1,2,3,4,5].delete_from_array([2,3,5]) # => [1,4]
37
37
  def delete_from_array(args)
38
- self.collect{ |x| x unless args.include?(x)}.compact
38
+ self.collect{ |x| x unless [args].flatten.include?(x)}.compact
39
39
  end
40
40
 
41
41
  # This calls the delete_from_array method, but will permantly replace the existing array.
@@ -83,7 +83,7 @@ class Array
83
83
  end
84
84
 
85
85
  # This will give you a count, as a Hash, of all the values in the Array.
86
- # %w{spam spam eggs ham eggs spam}.count # => {"eggs"=>2, "ham"=>1, "spam"=>3}
86
+ # %w{spam spam eggs ham eggs spam}.count # => {"eggs" => 2, "ham" => 1, "spam" => 3}
87
87
  def count
88
88
  k = Hash.new(0)
89
89
  self.each{|x| k[x] += 1}
@@ -91,7 +91,7 @@ class Array
91
91
  end
92
92
 
93
93
  # This will invert the index and the values and return a Hash of the results.
94
- # %w{red yellow orange}.invert # => {"red"=>0, "orange"=>2, "yellow"=>1}
94
+ # %w{red yellow orange}.invert # => {"red" => 0, "orange" => 2, "yellow" => 1}
95
95
  def invert
96
96
  h = {}
97
97
  self.each_with_index{|x,i| h[x] = i}
@@ -1,15 +1,83 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
3
  class ArrayTest < Test::Unit::TestCase
4
-
5
- def setup
4
+
5
+ def test_parse_splat_args
6
+ assert_equal [1,2,3], foo(1, 2, 3)
7
+ assert_equal [1,2,3], foo([1, 2, 3])
8
+ assert_equal 1, foo(1)
9
+ assert_equal({:mack => "is cool"}, foo(:mack => "is cool"))
10
+ assert_equal "hello", foo("hello")
11
+ assert_equal nil, foo(nil)
12
+ end
13
+
14
+ def test_delete_from_array
15
+ a = [1,2,3,4,5]
16
+ assert_equal [1,2], a.delete_from_array([3,4,5])
17
+ a = [1,2,3,4,5]
18
+ assert_equal [1,2,4,5], a.delete_from_array([3])
19
+ a = [1,2,3,4,5]
20
+ assert_equal [1,2,4,5], a.delete_from_array(3)
21
+ end
22
+
23
+ def test_delete_from_array_bang
24
+ a = [1,2,3,4,5]
25
+ a.delete_from_array!([3,4,5])
26
+ assert_equal [1,2], a
27
+ a = [1,2,3,4,5]
28
+ a.delete_from_array!([3])
29
+ assert_equal [1,2,4,5], a
30
+ a = [1,2,3,4,5]
31
+ a.delete_from_array!(3)
32
+ assert_equal [1,2,4,5], a
33
+ end
34
+
35
+ def test_randomize
36
+ a = [1,2,3,4,5]
37
+ assert a.randomize != a
38
+ end
39
+
40
+ def test_randomize_bang
41
+ a = [1,2,3,4,5]
42
+ a.randomize!
43
+ assert a != [1,2,3,4,5]
6
44
  end
7
45
 
8
- def teardown
46
+ def test_pick_random
47
+ a = []
48
+ 1000.times {|i| a << i}
49
+ assert a.pick_random != 0
9
50
  end
10
51
 
11
- # replace this with tests of your own.
12
- def test_truth
13
- assert true
52
+ def test_random_each
53
+ a = []
54
+ 1000.times {|i| a << i}
55
+ b = []
56
+ a.random_each {|i| b << i}
57
+ assert a != b
14
58
  end
59
+
60
+ def test_subset
61
+ a = [1,2,3,4,5]
62
+ b = [2,3]
63
+ assert b.subset?(a)
64
+ assert !a.subset?(b)
65
+ assert b.subset?(b)
66
+ end
67
+
68
+ def test_count
69
+ a = %w{spam spam eggs ham eggs spam}
70
+ assert_equal({"eggs" => 2, "ham" => 1, "spam" => 3}, a.count)
71
+ end
72
+
73
+ def test_invert
74
+ a = %w{red yellow orange}
75
+ assert_equal({"red" => 0, "orange" => 2, "yellow" => 1}, a.invert)
76
+ end
77
+
78
+ private
79
+ def foo(*args)
80
+ return args.parse_splat_args
81
+ end
82
+
15
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mack_ruby_core_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates