Skip to content

Commit 7b78cf2

Browse files
committed
Improved yardoc macro placement.
1 parent 7e988ac commit 7b78cf2

File tree

3 files changed

+59
-51
lines changed

3 files changed

+59
-51
lines changed

lib/concurrent.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,62 @@
4949
#
5050
# @see http://linux.die.net/man/3/clock_gettime Linux clock_gettime(3)
5151

52+
# @!macro [new] copy_options
53+
#
54+
# ## Copy Options
55+
#
56+
# Object references in Ruby are mutable. This can lead to serious
57+
# problems when the {#value} of an object is a mutable reference. Which
58+
# is always the case unless the value is a `Fixnum`, `Symbol`, or similar
59+
# "primative" data type. Each instance can be configured with a few
60+
# options that can help protect the program from potentially dangerous
61+
# operations. Each of these options can be optionally set when the oject
62+
# instance is created:
63+
#
64+
# * `:dup_on_deref` When true the object will call the `#dup` method on
65+
# the `value` object every time the `#value` methid is called
66+
# (default: false)
67+
# * `:freeze_on_deref` When true the object will call the `#freeze`
68+
# method on the `value` object every time the `#value` method is called
69+
# (default: false)
70+
# * `:copy_on_deref` When given a `Proc` object the `Proc` will be run
71+
# every time the `#value` method is called. The `Proc` will be given
72+
# the current `value` as its only argument and the result returned by
73+
# the block will be the return value of the `#value` call. When `nil`
74+
# this option will be ignored (default: nil)
75+
#
76+
# When multiple deref options are set the order of operations is strictly defined.
77+
# The order of deref operations is:
78+
# * `:copy_on_deref`
79+
# * `:dup_on_deref`
80+
# * `:freeze_on_deref`
81+
#
82+
# Because of this ordering there is no need to `#freeze` an object created by a
83+
# provided `:copy_on_deref` block. Simply set `:freeze_on_deref` to `true`.
84+
# Setting both `:dup_on_deref` to `true` and `:freeze_on_deref` to `true` is
85+
# as close to the behavior of a "pure" functional language (like Erlang, Clojure,
86+
# or Haskell) as we are likely to get in Ruby.
87+
88+
# @!macro [attach] deref_options
89+
#
90+
# @option opts [Boolean] :dup_on_deref (false) Call `#dup` before
91+
# returning the data from {#value}
92+
# @option opts [Boolean] :freeze_on_deref (false) Call `#freeze` before
93+
# returning the data from {#value}
94+
# @option opts [Proc] :copy_on_deref (nil) When calling the {#value}
95+
# method, call the given proc passing the internal value as the sole
96+
# argument then return the new value returned from the proc.
97+
98+
# @!macro [attach] executor_and_deref_options
99+
#
100+
# @param [Hash] opts the options used to define the behavior at update and deref
101+
# and to specify the executor on which to perform actions
102+
# @option opts [Executor] :executor when set use the given `Executor` instance.
103+
# Three special values are also supported: `:task` returns the global task pool,
104+
# `:operation` returns the global operation pool, and `:immediate` returns a new
105+
# `ImmediateExecutor` object.
106+
# @!macro deref_options
107+
52108
# Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell,
53109
# F#, C#, Java, and classic concurrency patterns.
54110
#

lib/concurrent/agent.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,7 @@ class Agent
9393
#
9494
# @param [Object] initial the initial value
9595
#
96-
# @!macro [attach] executor_and_deref_options
97-
#
98-
# @param [Hash] opts the options used to define the behavior at update and deref
99-
# and to specify the executor on which to perform actions
100-
# @option opts [Executor] :executor when set use the given `Executor` instance.
101-
# Three special values are also supported: `:task` returns the global task pool,
102-
# `:operation` returns the global operation pool, and `:immediate` returns a new
103-
# `ImmediateExecutor` object.
104-
# @!macro deref_options
96+
# @!macro executor_and_deref_options
10597
def initialize(initial, opts = {})
10698
@value = initial
10799
@rescuers = []

lib/concurrent/atom.rb

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,7 @@ module Concurrent
1818
# new value to the result of running the given block if and only if that
1919
# value validates.
2020
#
21-
# @!macro [attach] copy_options
22-
# ## Copy Options
23-
#
24-
# Object references in Ruby are mutable. This can lead to serious
25-
# problems when the {#value} of an object is a mutable reference. Which
26-
# is always the case unless the value is a `Fixnum`, `Symbol`, or similar
27-
# "primative" data type. Each instance can be configured with a few
28-
# options that can help protect the program from potentially dangerous
29-
# operations. Each of these options can be optionally set when the oject
30-
# instance is created:
31-
#
32-
# * `:dup_on_deref` When true the object will call the `#dup` method on
33-
# the `value` object every time the `#value` methid is called
34-
# (default: false)
35-
# * `:freeze_on_deref` When true the object will call the `#freeze`
36-
# method on the `value` object every time the `#value` method is called
37-
# (default: false)
38-
# * `:copy_on_deref` When given a `Proc` object the `Proc` will be run
39-
# every time the `#value` method is called. The `Proc` will be given
40-
# the current `value` as its only argument and the result returned by
41-
# the block will be the return value of the `#value` call. When `nil`
42-
# this option will be ignored (default: nil)
43-
#
44-
# When multiple deref options are set the order of operations is strictly defined.
45-
# The order of deref operations is:
46-
# * `:copy_on_deref`
47-
# * `:dup_on_deref`
48-
# * `:freeze_on_deref`
49-
#
50-
# Because of this ordering there is no need to `#freeze` an object created by a
51-
# provided `:copy_on_deref` block. Simply set `:freeze_on_deref` to `true`.
52-
# Setting both `:dup_on_deref` to `true` and `:freeze_on_deref` to `true` is
53-
# as close to the behavior of a "pure" functional language (like Erlang, Clojure,
54-
# or Haskell) as we are likely to get in Ruby.
21+
# @!macro copy_options
5522
#
5623
# @see http://clojure.org/atoms Clojure Atoms
5724
class Atom < Synchronization::Object
@@ -66,14 +33,7 @@ class Atom < Synchronization::Object
6633
# intended new value. The validator will return true if the new value
6734
# is acceptable else return false (preferrably) or raise an exception.
6835
#
69-
# @!macro [attach] deref_options
70-
# @option opts [Boolean] :dup_on_deref (false) Call `#dup` before
71-
# returning the data from {#value}
72-
# @option opts [Boolean] :freeze_on_deref (false) Call `#freeze` before
73-
# returning the data from {#value}
74-
# @option opts [Proc] :copy_on_deref (nil) When calling the {#value}
75-
# method, call the given proc passing the internal value as the sole
76-
# argument then return the new value returned from the proc.
36+
# @!macro deref_options
7737
#
7838
# @raise [ArgumentError] if the validator is not a `Proc` (when given)
7939
def initialize(value, opts = {})

0 commit comments

Comments
 (0)