Skip to content

Instantly share code, notes, and snippets.

View jens's full-sized avatar

Jens Norrgrann jens

View GitHub Profile
current_path = File.expand_path(File.dirname(__FILE__))
require File.join(current_path.split("/").collect {|p| current_path.split("/" + p).first + "/" + p}.reverse.detect {|p| File.exist?(p + "/spec_helper.rb")}, 'spec_helper')
root = '/Users/henrik/Sites/auktion/spec/models/auction'
max = root.scan('/').length + 1
x = max.times { |i|
path = "#{root}/#{'../'*i}spec_helper.rb"
unless (found = Dir[path]).empty?
break(File.expand_path(found.first))
end
}
p x
@jens
jens / gist:318377
Created March 1, 2010 13:45
Load a class into a module without changing the class source file
require 'some/path/to/some_class.rb'
module MyNamespace end
MyNamespace::SomeClass = SomeClass
Object.send(:remove_const, :SomeClass)