@@ -35,7 +35,7 @@ Structure
35
35
class CardboardBox
36
36
37
37
- **Methods:** All method definitions should be preceded by a documentation comment.
38
- Use ``@param`` and ``@return`` to specify input(s) and output respectively .
38
+ Use ``@param``, ``@yield``, and ``@return`` to specify inputs and output.
39
39
For further details, refer to
40
40
:ref:`Type Declaration <code-documentation-type-declaration>` below.
41
41
@@ -48,33 +48,30 @@ Structure
48
48
# @return [ Tiger ] The transmogrified result.
49
49
def transmogrify(person)
50
50
51
+ - **Errors:** Use ``@raise`` to explain errors specific to the method.
52
+
53
+ .. code-block:: ruby
54
+
55
+ # @raise [ Errors::Validations ] If validation failed.
56
+ def validate!
57
+
51
58
- **Private Methods:** Private methods should be documented unless they are
52
59
so brief and straightforward that it is obvious what they do. Note that,
53
60
for example, a method may be brief and straightforward but the type of
54
- its parameter may not be obvious, in which case the parameter needs to
55
- be appropriately documented.
61
+ its parameter may not be obvious, in which case the parameter must be
62
+ appropriately documented.
56
63
57
64
.. code-block:: ruby
58
65
59
66
private
60
67
61
68
# Documentation is optional here.
62
- def my_internal_method
63
-
64
- - **Notes:** Use the ``@note`` macro to explain caveats, edge cases,
65
- and behavior which may surprise users.
66
-
67
- .. code-block:: ruby
68
-
69
- # Clear all stored data.
70
- #
71
- # @note This operation deletes data in the database.
72
- def erase_data!
69
+ def do_something_obvious
73
70
74
71
- **API Private:** Classes and public methods which are not intended for
75
72
external usage should be marked ``@api private``. This macro does not
76
73
require a comment.
77
-
74
+
78
75
Note that, because Mongoid's modules are mixed into application classes,
79
76
``private`` visibility of a method does not necessarily indicate its
80
77
status as an API private method.
@@ -86,6 +83,18 @@ Structure
86
83
# @api private
87
84
def dont_call_me_from_outside
88
85
86
+ - **Notes and TODOs:** Use ``@note`` to explain caveats, edge cases,
87
+ and behavior which may surprise users. Use ``@todo`` to record
88
+ follow-ups and suggestions for future improvement.
89
+
90
+ .. code-block:: ruby
91
+
92
+ # Clear all stored data.
93
+ #
94
+ # @note This operation deletes data in the database.
95
+ # @todo Refactor this method for performance.
96
+ def erase_data!
97
+
89
98
- **Deprecation:** Use the ``@deprecated`` macro to indicate deprecated
90
99
functionality. This macro does not require a comment.
91
100
@@ -286,3 +295,59 @@ Type Declaration
286
295
# @option **kwargs [ String | Array<String> ] :items The items(s) as Strings to include.
287
296
# @option **kwargs [ Integer ] :limit An Integer denoting the limit.
288
297
def buy_groceries(**kwargs)
298
+
299
+ - **Blocks:** Use ``@yield`` to specify when the method yields to a block.
300
+
301
+ .. code-block:: ruby
302
+
303
+ # @yield [ Symbol, Symbol, Symbol ] Evaluate the guess of who did the crime.
304
+ # Must take the person, location, and weapon used. Must return true or false.
305
+ def whodunit
306
+ yield(:mustard, :ballroom, :candlestick)
307
+ end
308
+
309
+ - **Blocks:** If the method explicitly specifies a block argument, specify the block
310
+ argument using ``@param`` preceded by an ampersand ``&``, and also specify ``@yield``.
311
+ Note ``@yield`` should be used even when method calls ``block.call`` rather than
312
+ ``yield`` internally.
313
+
314
+ .. code-block:: ruby
315
+
316
+ # @param &block The block.
317
+ # @yield [ Symbol, Symbol, Symbol ] Evaluate the guess of who did the crime.
318
+ # Must take the person, location, and weapon used. Must return true or false.
319
+ def whodunit(&block)
320
+ yield(:scarlet, :library, :rope)
321
+ end
322
+
323
+ # @param &block The block.
324
+ # @yield [ Symbol, Symbol, Symbol ] Evaluate the guess of who did the crime.
325
+ # Must take the person, location, and weapon used. Must return true or false.
326
+ def whodunit(&block)
327
+ block.call(:plum, :kitchen, :pipe)
328
+ end
329
+
330
+ - **Blocks:** Use ``@yieldparam`` and ``@yieldreturn`` instead of ``@yield`` where
331
+ beneficial for clarity.
332
+
333
+ .. code-block:: ruby
334
+
335
+ # @param &block The block.
336
+ # @yieldparam [ Symbol ] The person.
337
+ # @yieldparam [ Symbol ] The location.
338
+ # @yieldparam [ Symbol ] The weapon used.
339
+ # @yieldreturn [ true | false ] Whether the guess is correct.
340
+ def whodunit(&block)
341
+ yield(:peacock, :conservatory, :wrench)
342
+ end
343
+
344
+ - **Proc Args:** Proc arguments should use ``@param`` (not ``@yield``). The
345
+ inputs to the proc may be specified as subtype(s).
346
+
347
+ .. code-block:: ruby
348
+
349
+ # @param [ Proc<Integer, Integer, Integer> ] my_proc Proc argument which must
350
+ # take 3 integers and must return true or false whether the guess is valid.
351
+ def guess_three(my_proc)
352
+ my_proc.call(42, 7, 88)
353
+ end
0 commit comments