Class: Module

Inherits:
Object show all
Defined in:
lib/extensions/module.rb

Instance Method Summary collapse

Instance Method Details

#convert_security_of_methods(old_level = :public, new_level = :protected) ⇒ Object

Bulk converts the security level of methods in this Module from one level to another.



4
5
6
7
# File 'lib/extensions/module.rb', line 4

def convert_security_of_methods(old_level = :public, new_level = :protected)
  eval("#{old_level}_instance_methods").each{ |meth| self.send(new_level, meth) }
  self
end

#include_safely_into(*args) ⇒ Object

Includes this module into an Object, and changes all public methods to protected.

Examples:

module MyCoolUtils
  def some_meth
    "hi"
  end
  self.include_safely_into(FooController)
end

or:

MyCoolUtils.include_safely_into(FooController, SomeOtherClass)


20
21
22
23
24
25
26
27
# File 'lib/extensions/module.rb', line 20

def include_safely_into(*args)
  [args].flatten.each do |a|
    if a.is_a?(String) || a.is_a?(Symbol)
      a = a.to_s.constantize
    end
    a.send(:include, self.convert_security_of_methods)
  end
end