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.



485
486
487
# File 'lib/hookr.rb', line 485

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

#deep_copyObject



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

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

#lengthObject

Length minus the wildcard hook (if any)



498
499
500
501
502
503
504
# File 'lib/hookr.rb', line 498

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