Class: HookR::CallbackSet

Inherits:
SortedSet
  • Object
show all
Defined in:
lib/hookr.rb

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object

Fetch callback by either index or handle



481
482
483
484
485
486
487
# File 'lib/hookr.rb', line 481

def [](index)
  case index
  when Integer then detect{|cb| cb.index == index}
  when Symbol  then detect{|cb| cb.handle == index}
  else raise ArgumentError, "index must be Integer or Symbol"
  end
end

#each_reverse(&block) ⇒ Object



496
497
498
# File 'lib/hookr.rb', line 496

def each_reverse(&block)
  sort{|x, y| y <=> x}.each(&block)
end

#firstObject

get the first callback



490
491
492
493
494
# File 'lib/hookr.rb', line 490

def first
  each do |cb|
    return cb
  end
end