Skip to content

Instantly share code, notes, and snippets.

@rubyworks
rubyworks / require_monitor.rb
Created February 1, 2010 08:52
Monitor Requires
BEGIN {
module Kernel
h = Hash.new
define_method(:requiree) do
h
end
r = method :require
define_method(:require) do |a|
r.call(a)
h[a] = caller
@rubyworks
rubyworks / openhash.rb
Created January 24, 2010 08:23
OpenHash is a hash with a #method_missing that routes to [] and []=.
# OpenHash is a hash with a #method_missing method
# that routes to [] and []=.
class OpenHash < Hash
def method_missing(s, *a)
case s
when /\?$/
self.key?(s.chomp('?'))
when /\=$/
self[s] = a[0]
else