Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

it would actually be:

  require 'bar'

  foo
because require is a regular method and the argument is a string (I mean, you could pass bar without quotes if the string was in a variable called bar, but that's not the scenario being discussed.)

> However, Ruby does have auto-loading conventions. So you could define “module Baz{ module Bar { def foo end; } }” in “baz/bar.rb” from the root of your project. You should then be able to call “Baz::Bar::foo()” from any other file in your project structure without a “require” at all. This is not standard Ruby IIRC

autoload is a Kernel method in Ruby core, so it is standard Ruby, but you have to explicitly register a file to be automatically loaded when a particular method is referenced.

Some systems additionally include code that does this for source files based on path.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: