From: Suraj Kurapati Date: 2009-06-03T13:16:50+09:00 Subject: Re: nfc 1.0.0 Released Eric Hodel wrote: > You have to require 'nfc' to get the autoload, so this won't work. I beg to differ; you need not require() before using autoload(): sun@yantram ~/tmp> cat nfc.rb NFC = Class.new do require 'singleton' include Singleton def find(*args) p :find => args end end.instance p :loaded_nfc sun@yantram ~/tmp> cat run_this.rb autoload :NFC, 'nfc' NFC.find('123') sun@yantram ~/tmp> multiruby run_this.rb VERSION = 1.8.7-p72 CMD = ~/.multiruby/install/1.8.7-p72/bin/ruby run_this.rb :loaded_nfc {:find=>["123"]} RESULT = 0 VERSION = 1.8.6-p368 CMD = ~/.multiruby/install/1.8.6-p368/bin/ruby run_this.rb :loaded_nfc {:find=>["123"]} RESULT = 0 VERSION = 1.9.1-p0 CMD = ~/.multiruby/install/1.9.1-p0/bin/ruby run_this.rb :loaded_nfc {:find=>["123"]} RESULT = 0 VERSION = jruby-1.2.0 CMD = ~/.multiruby/install/jruby-1.2.0/bin/ruby run_this.rb :loaded_nfc {:find=>["123"]} RESULT = 0 TOTAL RESULT = 0 failures out of 4 Passed: 1.8.6-p368, 1.8.7-p72, jruby-1.2.0, 1.9.1-p0 Failed: > Adding two files to do this is far lamer than Singleton. Why would you need two files? Because NFC is a gem? Since RubyGems overrides Kernel#require() and Kernel#autoload() uses Kernel#require(), the autoload approach should work even if loading NFC from a gem. -- Posted via http://www.ruby-forum.com/.