Class: Ragot::Declaration

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Declaration

Returns a new instance of Declaration.



57
58
59
# File 'lib/ragot.rb', line 57

def initialize(klass)
  @klass, @ragots, @i = klass, {}, { klass => {}, klass.singleton_class => {} }
end

Class Method Details

.for(klass) ⇒ Object



53
54
55
# File 'lib/ragot.rb', line 53

def self.for(klass)
  (@collection ||= {})[klass] ||= new klass
end

Instance Method Details

#ragot(meth, options = {}, &block) ⇒ Object



67
68
69
70
# File 'lib/ragot.rb', line 67

def ragot(meth, options={}, &block)
  __incept_ragot(meth.to_sym, block, options) ||
    (@ragots[meth.to_sym] ||= []).push([meth.to_sym, block, options])
end

#trigger(meth) ⇒ Object



61
62
63
64
65
# File 'lib/ragot.rb', line 61

def trigger(meth)
  @ragots[meth] && @ragots[meth].shift(@ragots[meth].size).each do |r|
    __incept_ragot *r
  end
end