Module: SecureThisClass

Defined in:
lib/buzzcore/misc_utils.rb

Overview

include this at the top of a class to protect it from baddies. eg. + nearly all ancestor public_instance_methods will be hidden + inspect will only return the class name + methods will return public methods

Class Method Summary collapse

Class Method Details

.hack(aClass, aOptions = {}) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/buzzcore/misc_utils.rb', line 358

def self.hack(aClass,aOptions={})
  include_actions = (aOptions[:include] || aClass.public_instance_methods.clone)
  exclude_actions = ['class','public_methods'] | (aOptions[:exclude] || [])
  actions_to_hide = include_actions-exclude_actions
  aClass.class_eval do
    actions_to_hide.each { |m| protected m.to_sym }

    def inspect
      return self.class.name
    end

    def methods
      public_methods
    end
  end
end