tags:

views:

55

answers:

1

Is there a simple way to load a class from a URL in Ruby? I'm looking for something analogous to Java's URL class loader.

Example:

require 'http://github.com/outoftime/sunspot/blob/master/lib/light_config.rb'

  • or -

require 'http://www.codehost.com/application.tgz' (signed archive containing multiple files?)

I'm considering adding a custom function to load the classes from the URL, perform security checks, then call something like eval(..) - but this approach seems a bit odd.

+2  A: 

http_require

There's also a gem called urirequire. It appears to work:

http://yagni.com/bar.rb:

#!/usr/bin/ruby1.8

def foo
  puts "foo"
end

foo.rb:

#!/usr/bin/ruby1.8

require 'urirequire'
require 'http://yagni.com/bar.rb'

foo     # => foo
Wayne Conrad
this is great, thanks!
CJ