require ‘rubygems’

require ‘rubygems’ will adjust the Ruby loadpath allowing you to successfully require the gems you installed through rubygems, without getting a LoadError: no such file to load — sinatra. From the rubygems-1.3.6 documentation: When RubyGems is required, Kernel#require is replaced with our own which is capable of loading gems on demand. When you call require … Read more

How to require a ruby file from another directory

require will search for files in only a set of locations referred to as the “Load Path.” You can view the load path by using the global variable $LOAD_PATH in a script or irb session. If it is not in the load path, it won’t find it. Ruby 1.9 introduced require_relative which searches using the … Read more

How to do multiple imports in Python?

For known module, just separate them by commas: import lib1, lib2, lib3, lib4, lib5 If you really need to programmatically import based on dynamic variables, a literal translation of your ruby would be: modnames = “lib1 lib2 lib3 lib4 lib5”.split() for lib in modnames: globals()[lib] = __import__(lib) Though there’s no need for this in your … Read more

Is require File.expand_path(…, __FILE__) the best practice?

In Ruby 1.9.2 + require_relative is probably the more correct way to do it. require was changed to not include your ‘.’ directory for security reasons. require_relative was added to provide a local-file solution for modules relative to your calling script’s path. You can search here on StackOverflow, particularly in “What is require_relative in Ruby?”, … Read more

Webpack and external libraries

According to the Webpack documentation, you can use the externals property on the config object “to specify dependencies for your library that are not resolved by webpack, but become dependencies of the output. This means they are imported from the enviroment while runtime [sic].” The example on that page illustrates it really well, using jQuery. … Read more

Load Lua-files by relative path

There is a way of deducing the “local path” of a file (more concretely, the string that was used to load the file). If you are requiring a file inside lib.foo.bar, you might be doing something like this: require ‘lib.foo.bar’ Then you can get the path to the file as the first element (and only) … Read more