Class: NotifyMash
- Inherits:
- BasicObject
- Defined in:
- lib/vagabond/notify_mash.rb
Instance Method Summary collapse
- #add_notification(&block) ⇒ Object
-
#initialize(*args) ⇒ NotifyMash
constructor
A new instance of NotifyMash.
- #method_missing(sym, *args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ NotifyMash
Returns a new instance of NotifyMash.
5 6 7 8 |
# File 'lib/vagabond/notify_mash.rb', line 5 def initialize(*args) @notifications = [] @mash = ::Mash.new(*args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vagabond/notify_mash.rb', line 14 def method_missing(sym, *args) start_state = @mash.hash result = @mash.send(sym, *args) if(start_state != @mash.hash) @notifications.each do |notify| notify.call(self) end end result end |
Instance Method Details
#add_notification(&block) ⇒ Object
10 11 12 |
# File 'lib/vagabond/notify_mash.rb', line 10 def add_notification(&block) @notifications << block end |