andand 1.1.1 → 1.2.0

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.
@@ -6,3 +6,5 @@
6
6
  * fixed specifications
7
7
  * 3 minor enhancement
8
8
  * tap is now a synonym for me
9
+ * 4 minor enhancement
10
+ * Object#dont
@@ -36,6 +36,16 @@ module AndAnd
36
36
 
37
37
  alias :tap :me
38
38
 
39
+ def dont (p = nil)
40
+ if block_given?
41
+ self
42
+ elsif p
43
+ self
44
+ else
45
+ MockReturningMe.new(self)
46
+ end
47
+ end
48
+
39
49
  end
40
50
 
41
51
  end
@@ -1,8 +1,8 @@
1
1
  module Andand #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 1
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -33,7 +33,7 @@
33
33
  <h1>Object#andand</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/andand"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/andand" class="numbers">1.1.1</a>
36
+ <a href="http://rubyforge.org/projects/andand" class="numbers">1.2.0</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;andand&#8217;</h1>
39
39
 
@@ -105,16 +105,38 @@ list_of_lists.detect { ...elided... }.andand.inject(42) { ...elided ... }
105
105
  =&gt; [2, 4, 6, 8]
106
106
  </pre>
107
107
 
108
- <h2>Demonstration of usage</h2>
108
+ <h3>Doctor, it hurts when I do that</h3>
109
109
 
110
110
 
111
- <p>See above.</p>
111
+ <p><strong>Don&#8217;t do that!</strong></p>
112
112
 
113
113
 
114
+ <p>The popular use case for Object#tap is poor man&#8217;s debugging:</p>
115
+
116
+
117
+ <pre>
118
+ blah.sort.grep( /foo/ ).tap { |xs| p xs }.map { |x| x.blah }
119
+ </pre>Perhaps you want to remove the tap, you can delete it:
120
+
121
+ <pre>
122
+ blah.sort.grep( /foo/ ).tap { |xs| p xs }.map { |x| x.blah }
123
+ </pre>Or, you can change it to <code>.dont</code>:
124
+
125
+ <pre>
126
+ blah.sort.grep( /foo/ ).dont { |xs| p xs }.map { |x| x.blah }
127
+ </pre>Like <code>.andand</code> and <code>.tap</code>, <code>.dont</code> works with arbitrary methods, not just blocks:
128
+
129
+ <pre>
130
+ (1..10).to_a.reverse!
131
+ =&gt; [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
132
+ (1..10).dont.to_a.reverse!
133
+ =&gt; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
134
+ </pre>
135
+
114
136
  <h2>A little more background</h2>
115
137
 
116
138
 
117
- <p><a href="http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html">Object#andand &#38; Object#me in Ruby</a></p>
139
+ <p><a href="http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html">Object#andand &#38; Object#me in Ruby</a> explains the original motivations, as well as providing links to similar implementations you may want to consider. A few people have pointed out that Object#andand is similar to Haskell&#8217;s <code>Maybe</code> monad. <a href="http://blog.pretheory.com/arch/2008/02/the_maybe_monad_in_ruby.php">The Maybe Monad in Ruby</a> is a good introduction for Ruby programmers.</p>
118
140
 
119
141
 
120
142
  <h2>How to submit patches</h2>
@@ -132,12 +154,18 @@ list_of_lists.detect { ...elided... }.andand.inject(42) { ...elided ... }
132
154
  <p>This code is free to use under the terms of the <a href="http://en.wikipedia.org/wiki/MIT_License"><span class="caps">MIT</span> license</a>.</p>
133
155
 
134
156
 
157
+ <h2>Shout Out</h2>
158
+
159
+
160
+ <p><a href="http://mcommons.com/">Mobile Commons</a>. Huge.</p>
161
+
162
+
135
163
  <h2>Contact</h2>
136
164
 
137
165
 
138
166
  <p>Comments are welcome. Send an email to <a href="mailto:raganwald+rubyforge@gmail.com">Reginald Braithwaite</a>.</p>
139
167
  <p class="coda">
140
- <a href="http://weblog.raganwald.com">Reginald Braithwaite</a>, 10th February 2008<br>
168
+ <a href="http://weblog.raganwald.com">Reginald Braithwaite</a>, 15th February 2008<br>
141
169
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
142
170
  </p>
143
171
  </div>
@@ -57,14 +57,35 @@ Ruby 1.9 introduces "Object#tap":http://moonbase.rydia.net/mental/blog/programmi
57
57
  [1, 2, 3, 4, 5].tap.pop.map { |n| n * 2 }
58
58
  => [2, 4, 6, 8]
59
59
  </pre>
60
-
61
- h2. Demonstration of usage
62
60
 
63
- See above.
61
+ h3. Doctor, it hurts when I do that
62
+
63
+ *Don't do that!*
64
+
65
+ The popular use case for Object#tap is poor man's debugging:
66
+
67
+ <pre>
68
+ blah.sort.grep( /foo/ ).tap { |xs| p xs }.map { |x| x.blah }
69
+ </pre>Perhaps you want to remove the tap, you can delete it:
70
+
71
+ <pre>
72
+ blah.sort.grep( /foo/ ).tap { |xs| p xs }.map { |x| x.blah }
73
+ </pre>Or, you can change it to @.dont@:
74
+
75
+ <pre>
76
+ blah.sort.grep( /foo/ ).dont { |xs| p xs }.map { |x| x.blah }
77
+ </pre>Like @.andand@ and @.tap@, @.dont@ works with arbitrary methods, not just blocks:
78
+
79
+ <pre>
80
+ (1..10).to_a.reverse!
81
+ => [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
82
+ (1..10).dont.to_a.reverse!
83
+ => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
84
+ </pre>
64
85
 
65
86
  h2. A little more background
66
87
 
67
- "Object#andand & Object#me in Ruby":http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html
88
+ "Object#andand & Object#me in Ruby":http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html explains the original motivations, as well as providing links to similar implementations you may want to consider. A few people have pointed out that Object#andand is similar to Haskell's @Maybe@ monad. "The Maybe Monad in Ruby":http://blog.pretheory.com/arch/2008/02/the_maybe_monad_in_ruby.php is a good introduction for Ruby programmers.
68
89
 
69
90
  h2. How to submit patches
70
91
 
@@ -76,6 +97,10 @@ h2. License
76
97
 
77
98
  This code is free to use under the terms of the "MIT license":http://en.wikipedia.org/wiki/MIT_License.
78
99
 
100
+ h2. Shout Out
101
+
102
+ "Mobile Commons":http://mcommons.com/. Huge.
103
+
79
104
  h2. Contact
80
105
 
81
106
  Comments are welcome. Send an email to "Reginald Braithwaite":mailto:raganwald+rubyforge@gmail.com.
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: andand
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2008-02-10 00:00:00 -05:00
6
+ version: 1.2.0
7
+ date: 2008-02-15 00:00:00 -05:00
8
8
  summary: adds guarded method invocation to Ruby
9
9
  require_paths:
10
10
  - lib