20140716

Ruby: Difference between require and load

Load
  • loads a file (you were right!)
  • As it loads a file, it has to have the extension and a path depending on its location
File:
hello.rb

    p 'Hi there'   
  
  
File:
test1.rb

    load 'hello.rb'
    p 'Willma'
  
  
Require
  • require is smarter than load.
  • It loads a library and prevents you to load it twice. If you try to do so... it will print "false" like saying "dumb" to you.
  • You don't need to specify the rb extension. You can include the path depending on its location
File:
hello.rb

    p 'Hi there'   
  
  
File:
test1.rb

    require 'hello'
    p 'Willma'
  
  

0 comentarios:

Publicar un comentario

Con la tecnología de Blogger.