File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 111
111
# Current price: 112
112
112
# Current price: 79
113
113
# --- 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
114
138
module Observable
115
139
116
140
#
You can’t perform that action at this time.
0 commit comments