`
ltl3884
  • 浏览: 131997 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

file path

阅读更多
一直能看到一些gem里面会有这样一句代码:
$:.unshift File.expand_path('..', __FILE__)
这句话是干什么用的呢
$:就是ruby的一个全局变量,也叫$LOAD_PATH,功能就是java中的classpath,用来加载类库的,当你require某个文件时,ruby就会从这个变量的值去查找,找不到会报LoadError。这个值其实就是一个包含了类库绝对路径的数组。

__FILE__这个变量代表文件自己的文件名,在foo.rb中puts__FILE__,结果就是foo.rb。

File.expand_path可以把路径转换成绝对路径,假设有这样一个文件/Users/kenshin/foo.rb,里面有File.expand_path('..', __FILE__),返回的结果就是/Users/kenshin。

unshift是数组的一个方法,功能就是把指定的值加到数组的最前面,[3,4].unshift(1,2) => [1,2,3,4]

所以这段代码的意思就是把当前文件所在的目录加到ruby的loadpath的最前面,在require文件时,ruby就会先从当前目录下去查找了。
分享到:
评论

相关推荐

    MAC Get File Path(mac拷贝文件路径)

    MAC Get File Path文件夹右键快速拷贝路径,已经测试可用,直接安装。

    Find_File_Path.rar_FILE_PA_List All Files_find .file path

    此程序根据给出的文件路径(可以粘贴路径、可以选择路径)搜索在这个路径下的具体后缀的所有文件,将结果在列表视图控件框中显示。程序中搜索的是所有.cpp文件。

    Android代码-LogToFile

    LogToFile ↓支持一下 Android a simple and practical to print ...Log File Path: If the SD card or external memory exists, the SD Android data package name files Log logs.txt If there is an SD card or ex

    File-Path-2.08.tar.gz

    File-Path-2.08.tar.gz

    Get File Path

    获取IOS APP的各个文件夹目录地址。

    gtk theme 格式详解

    file = <<Relative File Path>> border = {INT_LEFT, INT_RIGHT, INT_TOP, INT_BOTTOM} stretch = TRUE|FALSE gap_file = <<Relative File Path>> gap_border = {INT_LEFT, INT_RIGHT, INT_TOP, INT_BOTTOM} ...

    SoFixer.exe

    Useage: SoFixer (s)> -s sourcefile -o generatefile ... -s --source sourceFilePath Source file path -o --output generateFilePath Generate file path -h --help Display this information

    extraIdFromFile

    this is a java file ,it can extra anyfile,like jsp,jsf,html.you can extra anything you like,you just need to config the file path and extra start character,and extra end character,for example,you want...

    VS2010单元测试的coverage文件转换为xml文件源代码

    coveragePath: xx.coverage file path. dllPath: the directory of unit test project's dll. xmlPath: the xml path for output. example: Coverage2xml e:\data.coverage e:\debug e:\xx.xml

    获取文件路径「Get file path」-crx插件

    获取指定站点的文件路径。 根据指定规则获取网站的...https://github.com/Riuujin/get-file-path-chrome-extension更改:1.0.3-更新了相关性以修复安全性问题。 1.0.4-更新了相关性以修复安全性问题。 支持语言:English

    Get file path-crx插件

    语言:English 获取指定站点的文件路径。 根据指定规则获取网站的文件...https://github.com/Riuujin/get-file-path-chrome-extension更改:1.0.3-更新了相关性以修复安全性问题。 1.0.4-更新了相关性以修复安全性问题。

    Android代码-RetroTextEditor

    The fixed default file path is Documents/click.dummer.textthing/notes.txt . If you open the app, this file will be opened, created and used for store. There is no file manager integrated! You can ...

    zxing.jar.

    File file new File path ; if file getParentFile exists { file getParentFile mkdirs ; } MatrixToImageWriter writeToFile byteMatrix format file ; MatrixToImageWriter ...

    apkpatch-1.0.3.zip

    -f,--from <loc> new Apk file path. -k,--keystore <loc> keystore path. -n,--name <name> patch name. -o,--out <dir> output dir. -p,--kpassword <***> keystore password. -t,--to <loc> old Apk file ...

    获取最接近现在时间的File(Uipath:Lambda&Linq;)

    Uipath调用Lambda & LinQ获取目录下最接近现在时间的File

    MySQL修改innodb_data_file_path参数的一些注意事项

    innodb_data_file_path用来指定innodb tablespace文件,如果我们不在My.cnf文件中指定innodb_data_home_dir和innodb_data_file_path那么默认会在datadir目录下创建ibdata1 作为innodb tablespace。 说明 在测试环境...

    matlab开发-ffpathfindfilepath文件路径

    matlab开发-ffpathfindfilepath文件路径。函数从matlabpath或系统路径中查找文件名的完整目录名。

    ESRI shape files to SVG files(源码)

    -shp=xxx 'xxx' means input shape file path. -svg=xxx 'xxx' means output svg file path. -uom=xxx 'xxx' means unit of meter in svg file. -width=xxx 'xxx' means output svg width, ignored if uom ...

    (源码)Astyle 1.22 支持中文路径名和文件名,支持文件夹命名中含有空格

    Astyle自动整理代码格式,修复支持中文文件名和中文路径名,文件夹名可以有空格字符。...+support file path and file name that containg chinese character; egAstyle --style=ansi E:\New Floder\测试.cpp

    Astyle 1.22 支持中文路径名和文件名,支持文件夹命名中含有空格

    Astyle自动整理代码格式,修复支持中文文件名和中文路径名,文件夹名可以有空格字符。...+support file path and file name that containg chinese character; egAstyle --style=ansi E:\New Floder\测试.cpp

Global site tag (gtag.js) - Google Analytics