load & require

  • The 'require' method will not look in the current directory for files to load(but you can use require './test.rb' to look in the current directory), but 'load' will.
  • If called more than once, 'require' will not reload the file while 'load' will. Suppose you're writing some code in a file and require it into irb. But it's failed, you fixed the failure and require it again, you won't get the fixed version. You need to use load to get the fixed version. So use 'require' in script file and 'load' in irb.
  • The 'require' method figures out the extension('.rb', '.so', '.dll'..) for you, but 'load' won't. So you need to use them like this:
  • require 'test'
    load 'test.rb'

     

posted @ 2015-05-29 16:44  LUCIEN06  阅读(106)  评论(0)    收藏  举报