How to run a Ruby script in Sublime Text 2 from project root

I have a Ruby project and I'd like to run the scripts directly from Sublime Text in place of having to run them in the terminal. I'm running Ubuntu 12.04 LTS if that matters at all. From the terminal I need to be located in the project root to make the script work: $ ruby path/to/file/file.rb If I try to run it from where the file is located it fails because they are requiring files

如何在项目根目录下的Sublime Text 2中运行Ruby脚本

我有一个Ruby项目,我希望直接从Sublime Text运行脚本,而不必在终端中运行它们。 如果有任何问题,我正在运行Ubuntu 12.04 LTS。 从终端我需要位于项目的根目录使脚本工作: $ ruby path/to/file/file.rb 如果我试图从文件所在的位置运行它,它会失败,因为它们需要项目中各个位置的文件。 如果我在Sublime Text(Ctrl + Shift + B)中运行脚本,它将以与从文件位置运行脚本相同的方式失败。 我该怎么做呢? 我怀疑这

Pry not stopping when called from a Ruby script that reads from stdin

I've created a console Ruby script that uses ARGF to load data from a file or stdin, that then calls Pry. This works great when I pass a file in (Pry pauses) but fails (Pry doesn't stop and just exits Ruby) when I pass my data using stdin. This is weird, anyone know why? I would like to pass data in via stdin and have Pry pause. Behold, an example script: require 'rubygems' requir

当从一个从stdin读取的Ruby脚本中调用时,撬不停

我创建了一个控制台Ruby脚本,它使用ARGF从文件或stdin加载数据,然后调用Pry。 当我通过一个文件(Pry暂停)但是失败时(Pry不停止并且刚刚退出Ruby),当我使用stdin传递我的数据时,这很好用。 这很奇怪,任何人都知道为什么? 我想通过stdin传递数据并让Pry暂停。 看一个脚本示例: require 'rubygems' require 'pry' def pry_it(str) binding.pry end pry_it(ARGF.read) 当我用ARGV中的一个文件调用这个应

Regex for extracting the substring of a given type from a string

Can someone help me in finding the regular expression for extracting the substring "CT23123" from the string "Andy Joe:CT23123" . I need a regex for extracting anything that is after ':' and is followed by two alphabets (can be in caps or small case) and 5 digits. 尝试这个: /:([a-zA-Z]{2}d{5})/ r = / (?<=:) # match a colon in a positive lookbehind [A-

用于从字符串中提取给定类型的子字符串的正则表达式

有人可以帮我找到从字符串“Andy Joe:CT23123”中提取子串“CT23123”的正则表达式。 我需要一个正则表达式来提取':'后面的任何内容,后面跟着两个字母(可以是大写或小写)和5位数字。 尝试这个: /:([a-zA-Z]{2}d{5})/ r = / (?<=:) # match a colon in a positive lookbehind [A-Z]{2} # match two letters d{5} # match 5 digits (?=D|z) # match a non-digit or the end of the string

Error installing ruby 1.9.3 from rvm on ubuntu 11.04

Error ruby-1.9.3-p0 - #extracted to /home/bhaarat/.rvm/src/ruby-1.9.3-p0 Fetching yaml-0.1.4.tar.gz to /home/bhaarat/.rvm/archives Extracting yaml-0.1.4.tar.gz to /home/bhaarat/.rvm/src Configuring yaml in /home/bhaarat/.rvm/src/yaml-0.1.4. Compiling yaml in /home/bhaarat/.rvm/src/yaml-0.1.4. ERROR: Error running 'make ', please read /home/bhaarat/.rvm/log/ruby-1.9.3-p0/yaml/make.l

在ubuntu 11.04上从rvm安装ruby 1.9.3时出错

错误 ruby-1.9.3-p0 - #提取到/home/bhaarat/.rvm/src/ruby-1.9.3-p0 将yaml-0.1.4.tar.gz提取到/home/bhaarat/.rvm/archives将yaml-0.1.4.tar.gz提取到/home/bhaarat/.rvm/src在/home/bhaarat/.rvm中配置yaml /src/yaml-0.1.4。 在/home/bhaarat/.rvm/src/yaml-0.1.4中编译yaml。 错误:运行'make'时出错,请阅读/home/bhaarat/.rvm/log/ruby-1.9.3-p0/yaml/make.log将yaml安装到/home/bhaarat/.rvm/usr错误:

Problem installing Ruby 1.9.2 on Mac OS Lion

I am running Lion, utilizing Xcode 4, have RVM and homebrew installed but am only able to run ruby 1.8.7 spurvis:~ rogue$ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] spurvis:~ rogue$ I've read through several threads related to this topic but nothing seems to work for my problem: spurvis:~ rogue$ rvm install 1.9.2 Installing Ruby from source

在Mac OS Lion上安装Ruby 1.9.2时出现问题

我正在运行Lion,利用Xcode 4,安装了RVM和自制软件,但只能运行Ruby 1.8.7 spurvis:~ rogue$ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] spurvis:~ rogue$ 我已阅读了几个与此主题相关的主题,但似乎没有任何工作可以解决我的问题: spurvis:~ rogue$ rvm install 1.9.2 Installing Ruby from source to: /Users/rogue/.rvm/rubies/ruby-1.9.2-p290, this may take a

Why do I get an error installing Ruby 1.8.7

I get the following error when trying to RVM install 1.8.7-p302: shawn-taylors-macbook-pro-2:~ shawntaylorphoto$ rvm install 1.8.7-p302 ... ERROR: Error running ' ./configure --prefix=/Users/shawntaylorphoto/.rvm/rubies/ruby-1.8.7-p302 --enable-shared --disable-install-doc ', please read /Users/shawntaylorphoto/.rvm/log/ruby-1.8.7-p302/configure.log ERROR: There has been an error while runn

为什么安装Ruby 1.8.7时出现错误?

尝试RVM安装1.8.7-p302时出现以下错误: shawn-taylors-macbook-pro-2:~ shawntaylorphoto$ rvm install 1.8.7-p302 ... ERROR: Error running ' ./configure --prefix=/Users/shawntaylorphoto/.rvm/rubies/ruby-1.8.7-p302 --enable-shared --disable-install-doc ', please read /Users/shawntaylorphoto/.rvm/log/ruby-1.8.7-p302/configure.log ERROR: There has been an error while running configure. Halting the

Get current stack trace in Ruby without raising an exception

I want to log the current backtrace (stacktrace) in a Rails 3 app without an exception occurring. Any idea how? Why do I want this? I'm trying to trace the calls that are made when Rails looks for a template so that I can choose a part of the process to override (because I want to change the view path for a particular subclassed controller of mine). I'd like to call it from the file

在Ruby中获取当前堆栈跟踪而不引发异常

我想在Rails 3应用程序中记录当前的回溯(stacktrace),而不会发生异常。 任何想法如何? 我为什么要这样? 我试图追踪Rails寻找模板时所做的调用,以便我可以选择部分流程进行覆盖(因为我想更改我的特定子类控制器的视图路径)。 我想从文件中调用它: gemsactionpack-3.2.3libaction_dispatchmiddlewaretemplatesrescuesmissing_template.erb 。 我知道这不是最佳做法,但我知道它是从搜索模板的位置开始的栈的下游。

Undefined local variable based on syntax in Ruby

In the following Ruby code, #! /usr/bin/env ruby x = true y = x and z = y puts "z: #{z}" It will output z: true , as expected. But in the following one, which I expect to have the same behavior: #! /usr/bin/env ruby x = true z = y if y = x puts "z: #{z}" It results in undefined local variable or method 'y' for main:Object (NameError) Why is that? I understood I am doing an ass

未定义的本地变量基于Ruby中的语法

在以下Ruby代码中, #! /usr/bin/env ruby x = true y = x and z = y puts "z: #{z}" 如预期的那样,它将输出z: true 。 但在下面的一个中,我期望它有相同的行为: #! /usr/bin/env ruby x = true z = y if y = x puts "z: #{z}" 它导致 未定义的局部变量或方法'y'for main:Object(NameError) 这是为什么? 我明白我正在做一个任务,并隐式检查赋值,以确定是否运行z = y 。 我也明白,如果我在x = 5行

can't install gem 'twitter

When trying to bundle install get error. I get the same error with empty project. Installing libv8 (3.3.10.4) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. C:/Ruby192/bin/ruby.exe extconf.rb *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. C

不能安装宝石'推特

当试图捆绑安装获取错误。 我得到空项目相同的错误。 Installing libv8 (3.3.10.4) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. C:/Ruby192/bin/ruby.exe extconf.rb *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more

What is the difference between include and extend in Ruby?

Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me. include : mixes in specified module methods as instance methods in the target class extend : mixes in specified module methods as class methods in the target class So is the major difference just this or is a bigger dragon lurking? eg module ReusableModule def module_method puts "Module

在Ruby中包含和扩展有什么区别?

刚开始讨论Ruby元编程。 mixin /模块总是会让我困惑。 包括 :在指定的模块方法中混合使用目标类中的实例方法 扩展 :将指定的模块方法混合为目标类中的类方法 那么这个主要区别就在这个还是一个更大的龙潜伏? 例如 module ReusableModule def module_method puts "Module Method: Hi there!" end end class ClassThatIncludes include ReusableModule end class ClassThatExtends extend ReusableModule