module Refrigerator

Refrigerator allows for easily freezing core classes and modules.

Constants

CORE_MODULES

Array of strings containing class or module names.

OPTS

Default frozen options hash

Public Class Methods

check_require(file, opts=OPTS) click to toggle source

Check that requiring a given file does not modify any core classes. Options:

:depends

Require the given files before freezing the core (array of strings)

:modules

Define the given modules in the Object namespace before freezing the core (array of module name symbols)

:classes

Define the given classes in the Object namespace before freezing the core (array of either class name Symbols or array with class Name Symbol and Superclass name string)

:except

Don't freeze any of the classes modules listed (array of strings)

   # File lib/refrigerator.rb
29 def self.check_require(file, opts=OPTS)
30   require 'rubygems'
31   Array(opts[:depends]).each{|f| require f}
32   Array(opts[:modules]).each{|m| Object.const_set(m, Module.new)}
33   Array(opts[:classes]).each{|c, *sc| Object.const_set(c, Class.new(sc.empty? ? Object : eval(sc.first.to_s)))}
34   freeze_core(:except=>%w'Gem Gem::Specification Gem::Deprecate'+Array(opts[:exclude]))
35   require file
36 end
freeze_core(opts=OPTS) click to toggle source

Freeze core classes and modules. Options:

:except

Don't freeze any of the classes modules listed (array of strings)

   # File lib/refrigerator.rb
18 def self.freeze_core(opts=OPTS)
19   (CORE_MODULES - Array(opts[:except])).each{|m| eval(m).freeze}
20   nil
21 end