Module: Kungfuig::ClassMethods

Includes:
InstanceMethods
Defined in:
lib/kungfuig.rb

Instance Method Summary collapse

Methods included from InstanceMethods

#kungfuig, #option, #option!, #option?, #options

Instance Method Details

#aspect(meth, after = true) ⇒ Object



138
139
140
141
142
143
# File 'lib/kungfuig.rb', line 138

def aspect meth, after = true
  fail ArgumentError.new "Aspect must have a codeblock" unless block_given?
  fail NoMethodError.new "Aspect must be attached to existing method" unless instance_methods.include? meth.to_sym

  Kungfuig::Prepender.new(self, meth).public_send((after ? :after : :before), &Proc.new)
end

#aspectsObject



145
146
147
148
149
150
# File 'lib/kungfuig.rb', line 145

def aspects
  ancestors.select { |a| a.name.nil? && a.ancestors.include?(I★I) }
           .flat_map { |m| m.instance_methods(false) }
           .group_by { |e| e }
           .map { |k, v| [k, v.count] }.to_h
end

#kungfuigure(&block) ⇒ Object

A wrapper for the configuration block

Parameters:

  • block

    the block to be executed in the context of this module



134
135
136
# File 'lib/kungfuig.rb', line 134

def kungfuigure &block
  instance_eval(&block)
end