Neither ruby and nor irb can load .rb file in current directory
None of these worked for me, but this did: irb -I . >require ‘file’ => true
None of these worked for me, but this did: irb -I . >require ‘file’ => true
Generally speaking, the “exports” field superseded the “module” field. “module” itself has never been an official standard but it became so widespread that at some point it was a de facto standard. Note that the “module” field is still being used by TypeScript if tsconfig’s moduleResolution is set to node; see microsoft/TypeScript#50794 for more info. … Read more
Here’s how I’m using ActiveRecord outside of Rails: #!/usr/bin/ruby require ‘active_record’ require ‘mysql2’ # or ‘pg’ or ‘sqlite3’ ActiveRecord::Base.establish_connection( adapter: ‘mysql2’, # or ‘postgresql’ or ‘sqlite3’ database: ‘DB_NAME’, username: ‘DB_USER’, password: ‘DB_PASS’, host: ‘localhost’ ) # Note that the corresponding table is ‘orders’ class Order < ActiveRecord::Base end Order.all.each do |o| puts “o: #{o.inspect}” end
The use function: use ModuleName; is equivalent to the following code using the require function: BEGIN { require ModuleName; ModuleName->import; } The BEGIN block causes this code to run as soon as the parser sees it. The require loads the module or dies trying. And then the import function of the module is called. The … Read more
You can autoinclude everything under the lib folderand avoid these problems: Type this your file in config/application.rb config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += Dir[“#{config.root}/lib/**/”]
require “header” See the require entry in the Lua Reference manual. The file “header.lua” must be somewhere in Lua’s search path. You can see (and modify) the path at package.path See the package.path entry in the the Lua Reference Manual This wiki page describes ways of creating modules to load with require.
Generally speaking it is common practice to capitalize your constants. This is a convention which tells other programmers that the value is fixed. The javascript keyword const, though confusing is not a constant in that sense. I think that is where you got confused. A constant is a concept/construct. Not a primitive type within the … Read more
If you want to inline file contents from fs.readFileSync() calls, you can use brfs: var fs = require(‘fs’); var src = fs.readFileSync(__dirname + ‘/file.txt’); then do: browserify -t brfs main.js > bundle.js and src will be set to the contents of file.txt at compile time.
var Module = require(‘module’); var originalRequire = Module.prototype.require; Module.prototype.require = function(){ //do your thing here return originalRequire.apply(this, arguments); };