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



510
511
512
513
514
515
516
# File 'lib/hookr.rb', line 510

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



533
534
535
# File 'lib/hookr.rb', line 533

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

#firstObject

get the first callback



527
528
529
530
531
# File 'lib/hookr.rb', line 527

def first
  each do |cb|
    return cb
  end
end

#to_aObject



518
519
520
521
522
523
524
# File 'lib/hookr.rb', line 518

def to_a
  if frozen? && !@keys
    @hash.keys.sort
  else
    super
  end
end