require
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 can I make Node.js ‘require’ absolute? (instead of relative)
Use: var myModule = require.main.require(‘./path/to/module’); It requires the file as if it were required from the main JavaScript file, so it works pretty well as long as your main JavaScript file is at the root of your project… and that’s something I appreciate.
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
How do I change the order in which Meteor loads Javascript files?
According to the Meteor documentation, files are currently loaded in this order: Files in [project_root]/lib are loaded first Files are sorted by directory depth. Deeper files are loaded first. Files are sorted in alphabetical order. main.* files are loaded last. Source: http://docs.meteor.com/#structuringyourapp
PHPStorm: undefined variables caused by include/require
All above answers removes or suppress warnings which imho is not good solution. Best solution is to add header with doc block with used variables. Example: <?php /** * @var string $name * @var FormData $form */ ?> This will not only prevent from showing “Undefined variable” warning, but also document your code and makes … Read more
How do I rescue from a `require’: no such file to load in ruby?
rescue without arguments rescues only StandardError s. The LoadError (that is raised by a file not found) is not a StandardError but a ScriptError (see http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy). Therefore you have to rescue the LoadError explicitly, as MBO indicated.
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
Check if an include (or require) exists
I believe file_exists does work with relative paths, though you could also try something along these lines… if(!@include(“script.php”)) throw new Exception(“Failed to include ‘script.php'”); … needless to say, you may substitute the exception for any error handling method of your choosing. The idea here is that the if-statement verifies whether the file could be included, … Read more