Sha256: de7d0476a81cc8bebd468c1ba53773a6bff65b46248d44d6b5af9dd108122abc
Contents?: true
Size: 1.11 KB
Versions: 15
Compression:
Stored size: 1.11 KB
Contents
module Rib; end module Rib::Plugin def self.included mod mod.send(:include, Rib) class << mod attr_accessor :disabled def enable self.disabled = false if block_given? then yield else enabled? end end def disable self.disabled = true if block_given? then yield else enabled? end end def enabled? !disabled end def disabled? !!disabled end end snake_name = mod.name.sub(/(\w+::)+?(\w+)$/, '\2'). gsub(/([A-Z][a-z]*)/, '\\1_').downcase[0..-2] code = (%w[enable disable].map{ |meth| <<-RUBY def #{meth}_#{snake_name} &block #{mod.name}.#{meth}(&block) end RUBY } + %w[enabled? disabled?].map{ |meth| <<-RUBY def #{snake_name}_#{meth} &block #{mod.name}.#{meth}(&block) end RUBY }).join("\n") meta_rib = if respond_to?(:singleton_class) Rib.singleton_class else class << Rib; self; end end meta_rib.module_eval(code, __FILE__, __LINE__) end end
Version data entries
15 entries across 15 versions & 1 rubygems