Module: Kernel

Defined in:
lib/require/extra.rb,
lib/require/on.rb

Overview

         DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                 Version 2, December 2004

Copyleft meh. [http://meh.paranoid.pk | [email protected]]

         DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

++

Constant Summary collapse

RequireWatch =
Hash.new {|hash, key|
  hash[key] = []
}

Instance Method Summary collapse

Instance Method Details

#on_require(name, &block) ⇒ Object Also known as: on_required



21
22
23
24
25
26
27
# File 'lib/require/on.rb', line 21

def on_require (name, &block)
  if required?(name)
    block.call(name)
  else
    RequireWatch[name] << block
  end
end

#require!(what) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/require/extra.rb', line 24

def require! (what)
	begin
		require what; true
	rescue Exception
		false
	end
end

#required?(name, from = $") ⇒ Boolean Also known as: is_required?

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/require/extra.rb', line 14

def required? (name, from=$")
	regexp = /(\A|\/)#{Regexp.escape(name)}(\.[^.]+)?$/

	from.any? {|file|
		file =~ regexp
	}
end