require

require lib in RSpec with Ruby 1.9.2 brings “no such file to load”

删除回忆录丶 提交于 2019-12-31 20:17:51
问题 I am trying to upgrade one of my Rails projects to Ruby 1.9.2 . All went pretty well, but one RSpec test broke. In this test I require a Ruby lib : # file spec/models/my_lib_spec.rb require 'spec_helper' require 'lib/services/my_lib' describe "MyLib" do it "should do something" do ... The lib looks like this: # file lib/services/my_lib.rb class MyLib def self.do_something ... In Ruby 1.8.7 (REE) the test worked well: $ ruby -v ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin11.1.0], MBARI

How to require a file in node.js and pass an argument in the request method, but not to the module?

随声附和 提交于 2019-12-31 12:09:07
问题 I have a module.js that must be loaded; In order to work needs objectX; How do I pass the objectX to the module.js in the require method provided by node.js? thanks // my module.js objectX.add('abc'); // error: objectX is undefined I would like a way to do it, without having to change all my classes because would take a lot of time... and they way it is has good performance for the client side. (I mix clientfiles with serverfiles***) 回答1: The module that you write can export a single function

How to require a file in node.js and pass an argument in the request method, but not to the module?

不打扰是莪最后的温柔 提交于 2019-12-31 12:08:02
问题 I have a module.js that must be loaded; In order to work needs objectX; How do I pass the objectX to the module.js in the require method provided by node.js? thanks // my module.js objectX.add('abc'); // error: objectX is undefined I would like a way to do it, without having to change all my classes because would take a lot of time... and they way it is has good performance for the client side. (I mix clientfiles with serverfiles***) 回答1: The module that you write can export a single function

Neither ruby and nor irb can load .rb file in current directory

依然范特西╮ 提交于 2019-12-31 08:44:16
问题 I'm having a really noob problem with importing files in Ruby. I'm making a Ruby app in Windows XP. All the class files for the app are in "C:/Documents/Prgm/Surveyor_Ruby/lib" . But when I require a file in another file, neither ruby nor irb can find the required file. The current directory's contents: C:\Documents\Prgm\Surveyor_Ruby\lib>dir Volume in drive C has no label. Volume Serial Number is AAAA-BBBB Directory of C:\Documents\Prgm\Surveyor_Ruby\lib 10/09/2010 06:32 PM <DIR> . 10/09

Ruby Strange Error

强颜欢笑 提交于 2019-12-31 05:31:40
问题 Whenever I require a file in ruby or irb I get this error: LoadError: no such file to load -- (insert any filename).rb from <internal:lib/rubygems/custom_require>:29:in `require' from <internal:lib/rubygems/custom_require>:29:in `require' from (irb):1 from /usr/bin/irb1.9.1:12:in `<main>' It happens even if the file exists I am using ruby1.9.1 and to my knowledge, I have not installed rubygems. I am running on Ubuntu 10.10 Maverick Meerkat. Please help, this problem is very annoying! Thanks

Best practices for Express app structure

拜拜、爱过 提交于 2019-12-31 03:10:35
Node和Express没有一个相对严格的文件或者是文件夹结构,因此你可以按照自己的想法来构建你的web项目,特别是对一些小的项目来说,他很容易学习。 然而当你的项目变得越来越大,所面临的情况越来越复杂的时候,你的代码将变得很混乱。特别是当你的团队变大的时候,将会很难基于以前的代码工作,你必须要经常处理代码之间的冲突。 为了能够添加一些新的特性,处理一些新的场景,你就需要改变你的代码结构了。更重要的是,现在有需要方式来组织你的文件和你的代码,但是很难选择那种结果适合你。 你想要有一个项目结构:不同的文件或者是文件夹负责不同的任务。你想要你的项目在多人使用时变得简单,相互之间有尽量少的代码冲突,你想要你的代码看上去清洁优雅,而且想要你的项目能够很容易的添加一些新的特性。 同样的问题我们也遇到了,现在这些都可以解决了,下面有一个很好的方式来构建你的项目,这种结构能够改变你的现状解决上述遇到的问题。 我们的这个结构以 Model-View-Controller (MVC) 这种设计模式为基础,这种模式能够很好的分离项目不同模块的职责,使得你的代码干净,可维护。 下面就让我们来看一下,我们是怎样通过Express这个web框架来扩展上面说的MCV模式的。我们不会讨论MVC模式的优点,我们将会集中精力基于Express来实现这个模式,同时我们也会看到的其他很好的实践。

Assertions in abstract superclass scala creating NPE

走远了吗. 提交于 2019-12-31 03:06:08
问题 The following code, when entered in REPL abstract class A { val aSet: Set[Int]; require(aSet.contains(3)) } class B extends A { val aSet = Set(4,5,6) } new B() gives a null point exception, rather than an invariant failure. What would be the best idiom to solve this problem? Similar questions: Code Contracts: Invariants in abstract class Private constructor in abstract class Scala? and also online commentary: https://gist.github.com/jkpl/4932e8730c1810261381851b13dfd29d 回答1: When you declare

Node+express+multer 解决保存文件路径、获取文件信息、响应编码

半城伤御伤魂 提交于 2019-12-30 17:34:43
先引用fs、multer。 let express = require('express'); let multer = require('multer'); let fs = require('fs'); let path = require("path"); let router = express.Router(); router.post('/', multer({ //设置文件存储路径 dest: 'upload' //upload文件如果不存在则会自己创建一个。 }).single('file'), function (req, res, next) { if (req.file.length === 0) { //判断一下文件是否存在,也可以在前端代码中进行判断。 res.render("error", {message: "上传文件不能为空!"}); return } else { let file = req.file; let fileInfo = {}; console.log(file); fs.renameSync('./upload/' + file.filename, './upload/' + file.originalname);//这里修改文件名字,比较随意。 // 获取文件信息 fileInfo.mimetype = file.mimetype

lua require

≯℡__Kan透↙ 提交于 2019-12-30 01:54:38
环境: Lua5.1 LuaForWindows LuaForWindows的下载地址 http://files.luaforge.net/releases/luaforwindows/luaforwindows 正题: require作用类似于C/C++中的#include,其特性为: 1. 根据搜索目录加载指定模块 2. 判定模块是否已加载,避免重复加载 其实现原理:   对于require加载的模块数据是存储在package.loaded表中,其存储方式以模块名为key,以返回值(模块若无返回值,默认为true)为value进行存储的。比如运行如下程序: -- package.loaded的类型 print(type(package.loaded)) -- table -- 没有require模块文件 for i, v in pairs(package.loaded) do print(i,v) end --[[ >>>输出 string table: 006EDE40 debug table: 006EDF08 package table: 006EDAF8 _G table: 00501C88 io table: 006EDC88 os table: 006EDDC8 table table: 006EDB98 math table: 006EDEB8 ]]

lua加载函数require和dofile

浪尽此生 提交于 2019-12-30 01:53:42
lua加载函数require和dofile Lua提供高级的require函数来加载运行库。粗略的说require和dofile完成同样的功能但有两点不同: 1. require会搜索目录加载文件; 2. require会判断是否文件已经加载避免重复加载同一文件。 由于上述特征,require在Lua中是加载库的更好的函数。 (一) require   require使用的路径和普通我们看到的路径还有些区别,我们一般见到的路径都是一个目录列表。require的路径是一个模式列表,每一个模式指明一种由 虚文件名 (require的参数)转成实文件名的方法。更明确地说,每一个模式是一个包含可选的问号的文件名。匹配的时候Lua会首先将问号用虚文件名替换,然后看是否有这样的文件存在。如果不存在继续用同样的方法用第二个模式匹配。例如,路径如下: ?;?.lua;c:\windows\?;/usr/local/lua/?/?.lua 调用require "test"时会试着打开这些文件: test test.lua c:\windows\test /usr/local/lua/test/test.lua require关注的问题只有分号(模式之间的分隔符)和问号,其他的信息(目录分隔符,文件扩展名)在路径中定义。   为了确定路径,Lua首先检查 全局变量LUA_PATH是否为一个字符串