Class: HookR::HookSet

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

Constant Summary collapse

WILDCARD_HOOK =
HookR::Hook.new(:__wildcard__)

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Find hook by name.

TODO: Optimize this.



463
464
465
# File 'lib/hookr.rb', line 463

def [](key)
  detect {|v| v.name == key} or raise IndexError, "No such hook: #{key}"
end

#deep_copyObject



467
468
469
470
471
472
473
# File 'lib/hookr.rb', line 467

def deep_copy
  result = HookSet.new
  each do |hook|
    result << hook.dup
  end
  result
end

#lengthObject

Length minus the wildcard hook (if any)



476
477
478
479
480
481
482
# File 'lib/hookr.rb', line 476

def length
  if include?(WILDCARD_HOOK)
    super - 1
  else
    super
  end
end