module DefinedMethods::Singleton
Constants
- NOT_INCLUDED_PRIVATE_METHODS
Public Class Methods
methods_defined_in(object)
click to toggle source
# File lib/defined_methods/singleton.rb, line 35 def methods_defined_in(object) { object_name: object.to_s, object: object.singleton_class, methods: object.methods(false) - object.protected_methods(false), private: false, protected: false, singleton: true } end
private_methods_defined_in(object)
click to toggle source
# File lib/defined_methods/singleton.rb, line 46 def private_methods_defined_in(object) { object_name: object.to_s, object: object.singleton_class, methods: object.private_methods(false) - NOT_INCLUDED_PRIVATE_METHODS - methods_from_extended_modules(object) - methods_from_ancestors(object), private: true, protected: false, singleton: true } end
protected_methods_defined_in(object)
click to toggle source
# File lib/defined_methods/singleton.rb, line 57 def protected_methods_defined_in(object) { object_name: object.to_s, object: object.singleton_class, methods: object.protected_methods(false) - methods_from_extended_modules(object) - methods_from_ancestors(object), private: false, protected: true, singleton: true } end
Private Class Methods
methods_from_ancestors(object)
click to toggle source
# File lib/defined_methods/singleton.rb, line 81 def methods_from_ancestors(object) ancestors = object.ancestors - [object, Object, Kernel, BasicObject] methods = [] ancestors.each do |mod| methods = methods + mod.protected_methods(false) + mod.private_methods(false) end methods.flatten.uniq end
methods_from_extended_modules(object)
click to toggle source
# File lib/defined_methods/singleton.rb, line 70 def methods_from_extended_modules(object) extended_modules = object.singleton_class.included_modules - [Kernel] methods = [] extended_modules.each do |mod| methods = methods + mod.instance_methods(false) + mod.private_instance_methods(false) end methods.flatten.uniq end