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



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

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



511
512
513
# File 'lib/hookr.rb', line 511

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

#firstObject

get the first callback



505
506
507
508
509
# File 'lib/hookr.rb', line 505

def first
  each do |cb|
    return cb
  end
end

#to_aObject



496
497
498
499
500
501
502
# File 'lib/hookr.rb', line 496

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