module Kramdown::Utils::Configurable
Methods for registering configurable extensions.
Public Instance Methods
configurable(name)
click to toggle source
Create a new configurable extension called name
.
Three methods will be defined on the calling object which allow to use this configurable extension:
- configurables
-
Returns a hash of hashes that is used to store all configurables of the object.
- <name>(ext_name)
-
Return the configured extension
ext_name
. - add_<name>(ext_name, data=nil, &block)
-
Define an extension
ext_name
by specifying either the data as argument or by using a block.
# File lib/kramdown/utils/configurable.rb 27 def configurable(name) 28 singleton_class = (class << self; self; end) 29 singleton_class.send(:define_method, :configurables) do 30 @_configurables ||= Hash.new {|h, k| h[k] = {}} 31 end unless respond_to?(:configurables) 32 singleton_class.send(:define_method, name) do |data| 33 configurables[name][data] 34 end 35 singleton_class.send(:define_method, "add_#{name}".intern) do |data, *args, &block| 36 configurables[name][data] = args.first || block 37 end 38 end