Skip to content

Commit 62a94e3

Browse files
committed
add symbol usage to docs
1 parent 34fe0e0 commit 62a94e3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/observer.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,30 @@
111111
# Current price: 112
112112
# Current price: 79
113113
# --- Sun Jun 09 00:10:25 CDT 2002: Price below 80: 79
114+
#
115+
# === Usage with procs
116+
#
117+
# The +#notify_observers+ method can also be used with +proc+s by using
118+
# the +:call+ as +func+ parameter.
119+
#
120+
# The following example illustrates the use of a lambda:
121+
#
122+
# require 'observer'
123+
#
124+
# class Ticker
125+
# include Observable
126+
#
127+
# def run
128+
# # logic to retrieve the price (here 77.0)
129+
# changed
130+
# notify_observers(77.0)
131+
# end
132+
# end
133+
#
134+
# ticker = Ticker.new
135+
# warner = ->(price) { puts "New price received: #{price}" }
136+
# ticker.add_observer(warner, :call)
137+
# ticker.run
114138
module Observable
115139

116140
#

0 commit comments

Comments
 (0)