Module: Instance::ModuleExtensions

Defined in:
lib/instance.rb

Overview

ModuleExtensions provides some additional methods for Module and Class objects.

TODO: Are there any other module/class methods that need to be provided?

Constant Summary collapse

METHODS =

Store Object methods so they cannot be overriden by the delegate class.

{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.freeze_method(name) ⇒ Object



310
311
312
# File 'lib/instance.rb', line 310

def self.freeze_method(name)
  METHODS[name.to_sym] = Module.instance_method(name)
end

Instance Method Details

#method_definition(name) ⇒ Object Also known as: definition

Get a first-class method definition object.

Returns an unbound method object. [UnboundMethod]



353
354
355
# File 'lib/instance.rb', line 353

def method_definition(name)
METHODS[:instance_method].bind(@delegate).call(name)
end

#method_definitions(*selection) ⇒ Object Also known as: definitions

List of method definitions in a module or class.

selection - Any of ‘:public`, `:protected` or `:private` which

is used to select specific subsets of methods.

Returns [Array<Symbol>]



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/instance.rb', line 326

def method_definitions(*selection)
list = []

if selection.empty?
  list.concat METHODS[:instance_methods].bind(@delegate).call
end

selection.each do |s|
  case s
  when :public, :all
    list.concat METHODS[:public_instance_methods].bind(@delegate).call
  when :protected, :all
    list.concat METHODS[:protected_instance_methods].bind(@delegate).call
  when :private, :all
    list.concat METHODS[:private_instance_methods].bind(@delegate).call
  end
end

return list
end