Module: Bowline::Watcher::Base::ClassMethods

Defined in:
lib/bowline/watcher.rb

Instance Method Summary collapse

Instance Method Details

#watch(*names) ⇒ Object

Create a helper method to easily add new callbacks. Example:

watch :on_load
on_load { puts "Loaded!" }


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bowline/watcher.rb', line 39

def watch(*names)
	names.each do |name|
    # Because define_method only takes a block,
    # which doesn't accept multiple arguments
    script = <<-RUBY
      def #{name}(*args, &block)
        watcher.append(:#{name}, *args, &block)
      end
    RUBY
    instance_eval script
    			end
end