Tag: ruby

PG :: ConnectionBad – 无法连接到服务器:连接被拒绝

每当我运行我的轨道4.0服务器,我得到这个输出。 Started GET "/" for 127.0.0.1 at 2013-11-06 23:56:36 -0500 PG::ConnectionBad – could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port […]

为什么在Ruby中a = a“ nil`?

我看了这个video 。 为什么a = a评估nil如果a没有被定义? a = a # => nil b = c = q = c # => nil

如何使用reflection来获取参数名称

我想在Ruby中做一些相当重要的反思。 我想创build一个函数,它返callback用堆栈中各种调用函数参数的名称(只要一个更高就足够了,但为什么要停下来?)。 我可以使用Kernel.caller ,去文件和parsing参数列表,但这将是丑陋的,不可靠的。 我想要的function将以下列方式工作: module A def method1( tuti, fruity) foo end def method2(bim, bam, boom) foo end def foo print caller_args[1].join(",") #the "1" mean one step up the call stack end end A.method1 #prints "tuti,fruity" A.method2 #prints "bim, bam, boom" 我不介意使用ParseTree或类似的工具来完成这个任务,但是看Parsetree,不知道如何使用它来达到这个目的。 像这样创build一个C扩展是另一种可能,但是如果有人已经为我做了这个,那将会很好。 我可以看到,我可能需要某种C扩展。 我想这意味着我的问题是C扩展的组合最容易工作。 我不认为调用者+ ParseTree会是足够的。 至于为什么我想这样做,而不是说“自动debugging”,也许我应该说,我想用这个function来自动检查函数的调用和返回条件: def add x, y check_positive return […]

“for”和“Ruby”中的“each”

我刚刚有一个关于Ruby中的循环的问题。 这两种迭代方式是否有区别? # way 1 @collection.each do |item| # do whatever end # way 2 for item in @collection # do whatever end 只是想知道如果这些是完全一样的,或者如果可能有一个微妙的差异(可能当@collection是零)。

在Ruby中debugging1.9

你们在ruby 1.9中使用什么进行debugging? rdebug似乎不兼容..有没有什么东西在那里?

Heroku推送被拒绝,没有检测到雪松支持的应用程序

我正在用Rails 3.1.3创build一个Rails应用程序: git init git remote add heroku <my heroku repo> git add . git commit -a -m "First commit" git push heroku master 得到: Counting objects: 102, done. Delta compression using up to 4 threads. Compressing objects: 100% (86/86), done. Writing objects: 100% (102/102), 315.47 KiB, done. Total 102 (delta 3), reused 0 (delta […]

你更喜欢什么Ruby IDE?

我一直在使用Eclipse和RDT(不是RadRails),而且我对它很满意,但是我想知道你们是否知道任何像样的select。 我知道NetBeans现在也支持Ruby,但是我不确定它提供的是什么。 请列出您认为在build议使用IDE时非常出色或有用的function,以便于比较。 另外,我说Ruby,而不是Rails。 虽然Rails支持是一个优点,但我更喜欢没有以Rails为中心的东西。 它也应该在Linux和Solaris上可用。

检查一个数组是否存在于Ruby中的一个数组中

我有一个价值'Dog'和arrays['Cat', 'Dog', 'Bird'] 。 如何检查它是否存在于数组中而不循环? 有一个简单的方法来检查值是否存在,仅此而已?

无法在OS X上安装gem“El Capitan”

我无法在El Capitan Beta 5上安装并运行fakes3 gem。 我试过了: sudo gem install fakes3 ERROR: While executing gem … (Errno::EPERM) Operation not permitted – /usr/bin/fakes3 然后我试着用椰子树的方式做。 它适用于椰子树,但不适用于假货3。 mkdir -p $HOME/Software/ruby export GEM_HOME=$HOME/Software/ruby gem install cocoapods […] 1 gem installed gem install fakes3 ERROR: While executing gem … (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

如何在rails中定义自定义configurationvariables

我想知道如何将自定义configurationvariables添加到rails应用程序,以及如何在控制器中访问它们,例如我想能够在configuration文件中定义一个upload_directory,说development.rb,并能够在我的一个控制器。 其次我打算在我的应用程序中拥有S3上传支持,如果我想添加一个yaml文件和s3访问密钥,我如何在我的Rails应用程序中初始化它,以及如何访问我定义的值在那个configuration文件中。