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



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/buzzcore/misc_utils.rb', line 420

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