require

Is there a shorter way to require a file in the same directory in ruby?

孤人 提交于 2019-11-27 11:52:05
问题 Is there a shorter way to require a file located in the same directory (as the script being executed)? require File.expand_path(File.dirname(__FILE__) + '/some_other_script') I read that require "my_script" and require "./my_script" will actually load the script twice (ruby will not recognize that it is actually the same script), and this is the reason why File.expand_path is recommended: if it is used every time the script is required, then it will only be loaded once. It seems weird to me

require file as string

六眼飞鱼酱① 提交于 2019-11-27 11:24:22
问题 I'm using node + express and I am just wondering how I can import any file as a string. Lets say I have a txt file all I want is to load it into a variable as such. var string = require("words.txt"); I am against modules.exports = function(){ var string = "whatever"; return string; } 回答1: If it's for a (few) specific extension(s), you can add your own require.extensions handler: var fs = require('fs'); require.extensions['.txt'] = function (module, filename) { module.exports = fs.readFileSync

Ruby 'require' error: cannot load such file

元气小坏坏 提交于 2019-11-27 10:20:32
I've one file, main.rb with the following content: require "tokenizer.rb" The tokenizer.rb file is in the same directory and its content is: class Tokenizer def self.tokenize(string) return string.split(" ") end end If i try to run main.rb I get the following error: C:\Documents and Settings\my\src\folder>ruby main.rb C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- tokenizer.rb (LoadError) from C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require ' from main.rb:1:in `<main>' I just noticed that if I use load instead of require

nodejs、数据库(基本指令)基础要点总结

时间秒杀一切 提交于 2019-11-27 09:39:29
这是一个md文件 大家觉得需要可以直接复制粘贴到md文件下用html打开看,这样效果会好点 ### 客户端的JavaScript是怎样的 - 什么是 JavaScript? +是一个脚本语言 +运行在浏览器(浏览器的js解析内核 v8) +实现用户的交互 (interactive) + 变量 赋值 循环 逻辑 判断 分支 对象 函数。。。。 + dom 操作 + bom 操作 + ajax - JavaScript 的运行环境? +浏览器内核解析内核 es6 - 浏览器中的 JavaScript 可以做什么? - 浏览器中的 JavaScript 不可以做什么?(不安全) +访问数据库 +不能对文件进行操作 +对os 进行操作 +原因 是不安全 和浏览器运行机制有关 - 在开发人员能力相同的情况下编程语言的能力取决于什么? +cordova hbuilder 平台 platform +java java虚拟机 (运行平台) +php php虚拟机 +c# .net framework mono +js 解析内核 chrome v8 - JavaScript 只可以运行在浏览器中吗? +不是 ### 为什么是JavaScript + node js 不是因为js 产生的 + node 选择了js + Ryan dahl + 2009 2 月份 node有想法 + 2009 5 月份

[摘抄] 5.模块的加载机制

南楼画角 提交于 2019-11-27 08:59:00
5.模块的加载机制 CommonJS模块的加载机制是,输入的是被输出的值的拷贝,也就是说一旦输出一个值,模块内部的变化就影响不到这个值。 下面是一个模块文件 lib.js // lib.js var counter = 3; function incCounter(){ counter ++; } module.exports = { counter, incCounter } 上面代码输出内部变量 counter 和改写这个变量的内部方法 incCounter 。 然后加载上面的模块。 // main.js var counter = require('./lib').counter; var incCounter = require('./lib').incCounter; console.log(counter) //3 incCounter(); console.log(counter) //3 上面代码说明, counter 输出以后,lib.js模块内部的变化就影响不到 counter 了 # 5.1 require的内部处理流程 require 命令是CommonJS规范之中用来加载其他模块命令。 他其实不是一个全局命令,而是指向当前模块的 module.require 命令,而后者又调用Node的内部命令, Module._load 。 Module._load =

Use of require(lib) versus <script> in Electron apps

爱⌒轻易说出口 提交于 2019-11-27 08:21:30
问题 I don't have a handle on when to use require('jslib') versus <script src=""></script> in Electron content pages (e.g. index.html). With jQuery, I discovered that it needs to be loaded as follows: <script>window.$ = window.jQuery = require('./js/jquery-2.2.4.min.js');</script> I need to start using some other libraries (e.g. Handlebars, ds3.js, Bootstrap, etc.) and I am not sure if I should be loading those with the <script> tag or if I should require them. 回答1: Some libraries only expose

node.js module初步理解

爷,独闯天下 提交于 2019-11-27 08:13:07
https://www.cnblogs.com/dolphinX/p/3485260.html 在开发一个复杂的应用程序的时候,我们需要把各个功能拆分、封装到不同的文件,在需要的时候引用该文件。没人会写一个几万行代码的文件,这样在可读性、复用性和维护性上都很差,几乎所有的编程语言都有自己的模块组织方式,比如Java中的包、C#中的程序集等,node.js使用模块和包来组织,其机制实现参照了CommonJS标准,虽未完全遵守,但差距不大,使用起来非常简单。 什么是模块 在node.js中模块与文件是一一对应的,也就是说一个node.js文件就是一个模块,文件内容可能是我们封装好的一些JavaScript方法、JSON数据、编译过的C/C++拓展等,在 关于node.js的误会 提到过node.js的架构 其中http、fs、net等都是node.js提供的核心模块,使用C/C++实现,外部用JavaScript封装。 创建、加载模块 模块在node.js中的概念很简单,看看如何创建一个我们自己的模块供开发复用。 在node.js中创建模块非常简单,一个文件就是一个模块,所以我们创建一个test.js文件就创建了一个模块 test.js var name=''; function setName(n){ name=n; } function printName(){ console

TP5报错Fatal error: require(): Failed opening required '/home/www/xx/public/../thinkphp/start.php

自古美人都是妖i 提交于 2019-11-27 07:29:50
https://jingyan.baidu.com/article/afd8f4deb784fe34e386e97b.html https://www.cnblogs.com/300js/p/9224567.html PHP message: PHP Warning: require(/data/wwwroot/blog.sgfoot.com/bootstrap/autoload.php): failed to open stream: Operation not permitted in /data/wwwroot/blog.sgfoot.com/public/index.php on line 22 PHP message: PHP Fatal error: require(): Failed opening required '/data/wwwroot/blog.sgfoot.com/public/../bootstrap/autoload.php' (include_path='.:/usr/local/php/lib/php') in /data/wwwroot/blog.sgfoot.com/public/index.php on line 22" while reading response header from upstream, client: 114.243

Vue引入图片

丶灬走出姿态 提交于 2019-11-27 07:21:39
记录一下自己学vue的内容: 版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/z519671318/article/details/80015777 首先给图片地址绑定变量 **<template> <img :src="imgUrl"> </template>` 在script中设置变量 <script> //方法1.直接将图片引入为模块 require imgUrl from "../assets/test.png" //方法2.将imgUrl放在数据里 data(){ return { imgUrl:require("../assets/test.png") } } //方法3.在生命周期函数中设置 data(){ return { imgUrl:"" } } created(){ let urlTemp = "assets/test.png"; this.imgUrl = require("@/"+urlTemp) } </script>** 来源: https://blog.csdn.net/weixin_42555713/article/details/99546783

NodeJs : TypeError: require(…) is not a function

蹲街弑〆低调 提交于 2019-11-27 07:10:27
I am trying to require a file and afterwards pass it to a var. I am following this tutorial to create a authentication system. After writing the server.js file and trying to compile I got a bson error therefore I changed the line that required the release version of it in mongoose. Here are my code and error : server.js require('./app/routes')(app, passport); Error require('./app/routes')(app, passport); ^ TypeError: require(...) is not a function at Object.<anonymous> (d:\Node JS learning\WorkWarV2\server.js:38:24) at Module._compile (module.js:434:26) at Object.Module._extensions..js (module