Method: CodeEvents#ignore
- Defined in:
- lib/source/redshift/code_events.rb
#ignore(sym, &block) ⇒ Object
call-seq:
obj.ignore -> obj
obj.ignore(sym) -> obj
obj.ignore(sym, &proc) -> obj
Instructs obj to ignore the specified event, then returns obj.
In the first form, all event-related Proc objects not marked as “unignorable” are removed from obj.
obj.upon(:A, true) { puts '1st executed' } #=> obj
obj.upon(:A) { puts '2nd executed' } #=> obj
obj.upon(:B) { puts '3rd executed' } #=> obj
obj.ignore #=> obj
obj.fire(:A).fire(:B) #=> obj
produces:
1st executed
In the second form, only the ignorable Proc objects associated with the event sym are removed.
obj.upon(:A, true) { puts '1st executed' } #=> obj
obj.upon(:A) { puts '2nd executed' } #=> obj
obj.upon(:B) { puts '3rd executed' } #=> obj
obj.ignore(:A) #=> obj
obj.fire(:A).fire(:B) #=> obj
produces:
1st executed
3rd executed
In the third form, only the Proc object passed in as &proc is removed.
proc_1 = Proc.new { puts 'Proc 1 executed' } #=> #<Proc:0x3e78ee>
proc_2 = Proc.new { puts 'Proc 2 executed' } #=> #<Proc:0x3e888a>
obj.upon(:A, &proc_1) #=> obj
obj.upon(:A, &proc_2) #=> obj
obj.ignore(:A, &proc_1) #=> obj
obj.fire(:A) #=> obj
produces:
Proc 2 executed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/source/redshift/code_events.rb', line 134 def ignore(sym, &block) if sym name = sym.to_sym return self unless @code_events && events_group = @code_events[name] if block events_group.delete(block) unless `block.__block__.__unignorable__` else events_group.each {|proc| self.disregard(name, &proc) } end else @code_events.each_key {|name| self.disregard(name) } end return self end |