Module: Kernel

Defined in:
lib/categories.rb

Instance Method Summary collapse

Instance Method Details

#category(module_or_name, &block) ⇒ Object

defines a category. If module_or_name is a String or a Symbol then a new Module will be created in the current scope with this name. If a Module is passed then this Module will be used as the category Module.

If String responds to camelcase it will be camelcased for you.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/categories.rb', line 71

def category(module_or_name, &block)
  mod = nil
  if module_or_name.is_a? ::Module
    mod = module_or_name
  else
    module_or_name = module_or_name.to_s.camelcase if module_or_name.to_s.respond_to? :camelcase
    mod = ""
    mod = "::#{self}" if (self.is_a? ::Module or self.is_a? ::Class) and self.to_s != "main"
    mod = Object.module_eval("module #{mod}::#{module_or_name} ; end ; #{mod}::#{module_or_name}", __FILE__, __LINE__)
  end
  Class::Category.new(mod,&block)
end