class Expand::Manager
The primary way to access Manager
objects is to use the Expand
namespace method. @see Expand#namespace
Public Class Methods
for(context)
click to toggle source
# File lib/expand.rb, line 56 def self.for(context) unless context.is_a?(Module) context = context.to_s.split("::").inject(Object) do |base, mod| base.const_get(mod) end end new(context) end
new(namespace)
click to toggle source
@see Expand#namespace
# File lib/expand.rb, line 10 def initialize(namespace) @managed = namespace end
Public Instance Methods
apply(&block)
click to toggle source
# File lib/expand.rb, line 51 def apply(&block) instance_exec(@managed, &block) @managed end
create_class(name, parent: Object, &block)
click to toggle source
Create a class under the namespace for this object @example
create_class 'Other' do def do_something end end
@param name [String, Symbol] name to be used for the class @param parent [Class] an optional class to be used as the direct ancestor of the class @yield provide a block to be used when creating the class
@return [Class] the named class you created
# File lib/expand.rb, line 45 def create_class(name, parent: Object, &block) klass = Class.new(parent, &block) @managed.const_set(name, klass) klass end
create_module(name, &block)
click to toggle source
Create a module under the namespace for this object @example
create_module 'Another' do def do_something end end
@param name [String, Symbol] name to be used for the module @yield provide a block to be used when creating the module
@return [Module] the named module you created
# File lib/expand.rb, line 26 def create_module(name, &block) mod = Module.new(&block) @managed.const_set(name, mod) mod end