/opt/cpanel/ea-ruby27/root/usr/share/ruby/ruby-2.7.8
NameSizeModeActions
benchmark/-0755rm
bigdecimal/-0755rm
bundler/-0755rm
cgi/-0755rm
csv/-0755rm
delegate/-0755rm
did_you_mean/-0755rm
digest/-0755rm
drb/-0755rm
fiddle/-0755rm
forwardable/-0755rm
getoptlong/-0755rm
io/-0755rm
irb/-0755rm
json/-0755rm
logger/-0755rm
matrix/-0755rm
net/-0755rm
observer/-0755rm
open3/-0755rm
openssl/-0755rm
optparse/-0755rm
ostruct/-0755rm
pstore/-0755rm
psych/-0755rm
racc/-0755rm
rdoc/-0755rm
reline/-0755rm
rexml/-0755rm
rinda/-0755rm
ripper/-0755rm
rss/-0755rm
rubygems/-0755rm
singleton/-0755rm
syslog/-0755rm
timeout/-0755rm
tracer/-0755rm
unicode_normalize/-0755rm
uri/-0755rm
webrick/-0755rm
yaml/-0755rm
abbrev.rb35290644editdlrm
base64.rb33790644editdlrm
benchmark.rb184530644editdlrm
bigdecimal.rb240644editdlrm
bundler.rb237180644editdlrm
cgi.rb100370644editdlrm
coverage.rb3680644editdlrm
csv.rb556430644editdlrm
date.rb10660644editdlrm
debug.rb306240644editdlrm
delegate.rb113430644editdlrm
did_you_mean.rb38060644editdlrm
digest.rb28940644editdlrm
drb.rb500644editdlrm
English.rb62580644editdlrm
erb.rb295040644editdlrm
expect.rb22170644editdlrm
fiddle.rb17220644editdlrm
fileutils.rb492710644editdlrm
find.rb25260644editdlrm
forwardable.rb91300644editdlrm
getoptlong.rb157870644editdlrm
ipaddr.rb199890644editdlrm
irb.rb276030644editdlrm
json.rb18090644editdlrm
kconv.rb58610644editdlrm
logger.rb167920644editdlrm
matrix.rb617030644editdlrm
mkmf.rb885390644editdlrm
monitor.rb69200644editdlrm
mutex_m.rb22140644editdlrm
observer.rb59710644editdlrm
open-uri.rb260880644editdlrm
open3.rb223360644editdlrm
openssl.rb4690644editdlrm
optionparser.rb590644editdlrm
optparse.rb609190644editdlrm
ostruct.rb107850644editdlrm
pathname.rb165580644editdlrm
pp.rb159780644editdlrm
prettyprint.rb162760644editdlrm
prime.rb126700644editdlrm
pstore.rb150630644editdlrm
psych.rb217180644editdlrm
racc.rb1370644editdlrm
rdoc.rb50000644editdlrm
readline.rb1130644editdlrm
reline.rb132530644editdlrm
resolv-replace.rb18050644editdlrm
resolv.rb795640644editdlrm
ripper.rb24940644editdlrm
rss.rb29630644editdlrm
rubygems.rb391080644editdlrm
securerandom.rb95280644editdlrm
set.rb246220644editdlrm
shellwords.rb68160644editdlrm
singleton.rb41580644editdlrm
socket.rb447020644editdlrm
tempfile.rb112130644editdlrm
time.rb245900644editdlrm
timeout.rb40750644editdlrm
tmpdir.rb41420644editdlrm
tracer.rb66400644editdlrm
tsort.rb146420644editdlrm
un.rb102020644editdlrm
uri.rb30390644editdlrm
weakref.rb14730644editdlrm
webrick.rb68900644editdlrm
yaml.rb18450644editdlrm
Edit: /opt/cpanel/ea-ruby27/root/usr/share/ruby/ruby-2.7.8/observer.rb (5971B)
# frozen_string_literal: true # # Implementation of the _Observer_ object-oriented design pattern. The # following documentation is copied, with modifications, from "Programming # Ruby", by Hunt and Thomas; http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_patterns.html. # # See Observable for more info. # The Observer pattern (also known as publish/subscribe) provides a simple # mechanism for one object to inform a set of interested third-party objects # when its state changes. # # == Mechanism # # The notifying class mixes in the +Observable+ # module, which provides the methods for managing the associated observer # objects. # # The observable object must: # * assert that it has +#changed+ # * call +#notify_observers+ # # An observer subscribes to updates using Observable#add_observer, which also # specifies the method called via #notify_observers. The default method for # #notify_observers is #update. # # === Example # # The following example demonstrates this nicely. A +Ticker+, when run, # continually receives the stock +Price+ for its @symbol. A +Warner+ # is a general observer of the price, and two warners are demonstrated, a # +WarnLow+ and a +WarnHigh+, which print a warning if the price is below or # above their set limits, respectively. # # The +update+ callback allows the warners to run without being explicitly # called. The system is set up with the +Ticker+ and several observers, and the # observers do their duty without the top-level code having to interfere. # # Note that the contract between publisher and subscriber (observable and # observer) is not declared or enforced. The +Ticker+ publishes a time and a # price, and the warners receive that. But if you don't ensure that your # contracts are correct, nothing else can warn you. # # require "observer" # # class Ticker ### Periodically fetch a stock price. # include Observable # # def initialize(symbol) # @symbol = symbol # end # # def run # last_price = nil # loop do # price = Price.fetch(@symbol) # print "Current price: #{price}\n" # if price != last_price # changed # notify observers # last_price = price # notify_observers(Time.now, price) # end # sleep 1 # end # end # end # # class Price ### A mock class to fetch a stock price (60 - 140). # def self.fetch(symbol) # 60 + rand(80) # end # end # # class Warner ### An abstract observer of Ticker objects. # def initialize(ticker, limit) # @limit = limit # ticker.add_observer(self) # end # end # # class WarnLow < Warner # def update(time, price) # callback for observer # if price < @limit # print "--- #{time.to_s}: Price below #@limit: #{price}\n" # end # end # end # # class WarnHigh < Warner # def update(time, price) # callback for observer # if price > @limit # print "+++ #{time.to_s}: Price above #@limit: #{price}\n" # end # end # end # # ticker = Ticker.new("MSFT") # WarnLow.new(ticker, 80) # WarnHigh.new(ticker, 120) # ticker.run # # Produces: # # Current price: 83 # Current price: 75 # --- Sun Jun 09 00:10:25 CDT 2002: Price below 80: 75 # Current price: 90 # Current price: 134 # +++ Sun Jun 09 00:10:25 CDT 2002: Price above 120: 134 # Current price: 134 # Current price: 112 # Current price: 79 # --- Sun Jun 09 00:10:25 CDT 2002: Price below 80: 79 module Observable # # Add +observer+ as an observer on this object. So that it will receive # notifications. # # +observer+:: the object that will be notified of changes. # +func+:: Symbol naming the method that will be called when this Observable # has changes. # # This method must return true for +observer.respond_to?+ and will # receive *arg when #notify_observers is called, where # *arg is the value passed to #notify_observers by this # Observable def add_observer(observer, func=:update) @observer_peers = {} unless defined? @observer_peers unless observer.respond_to? func raise NoMethodError, "observer does not respond to `#{func}'" end @observer_peers[observer] = func end # # Remove +observer+ as an observer on this object so that it will no longer # receive notifications. # # +observer+:: An observer of this Observable def delete_observer(observer) @observer_peers.delete observer if defined? @observer_peers end # # Remove all observers associated with this object. # def delete_observers @observer_peers.clear if defined? @observer_peers end # # Return the number of observers associated with this object. # def count_observers if defined? @observer_peers @observer_peers.size else 0 end end # # Set the changed state of this object. Notifications will be sent only if # the changed +state+ is +true+. # # +state+:: Boolean indicating the changed state of this Observable. # def changed(state=true) @observer_state = state end # # Returns true if this object's state has been changed since the last # #notify_observers call. # def changed? if defined? @observer_state and @observer_state true else false end end # # Notify observers of a change in state *if* this object's changed state is # +true+. # # This will invoke the method named in #add_observer, passing *arg. # The changed state is then set to +false+. # # *arg:: Any arguments to pass to the observers. def notify_observers(*arg) if defined? @observer_state and @observer_state if defined? @observer_peers @observer_peers.each do |k, v| k.send v, *arg end end @observer_state = false end end end