I'm having a bit of trouble with a block in Ruby. I've created a class which monitors a directory using the fssm gem. When a change occurs I want to notify observers. I'm using the Observable module.
Code:
require 'fssm'
require 'observer'
class FSSM_Spike
include Observable
def initialize watcher
add_observer watcher
FSSM.monitor('./temp/', '**/*', :directories => true) do
update do |base, relative|
puts 'update'
notify_observers(self, 'update')
end
delete do |base, relative|
puts 'delete'
notify_observers(self, 'delete')
end
create do |base, relative|
puts 'create'
notify_observers(self, 'create')
end
end
end
end
Any observers which want to create an instance of FSSM_Spike must pass themselve to new. These then get added to the list observers. However, when a FSSM callback occurs, the method notifiy_observers is not known, as self in that context is FSSM::Path.
I tried adding another method to FSSM_Spike to see if I could call that but had the same result.
How can I call methods from within a block context?