问题:

我是ruby的新手,但在尝试安装capybara以在我的系统上运行测试时,我收到以下错误。 我在运行OSX

my_app$ gem install capybara-webkit
Building native extensions.  This could take a while...
ERROR:  Error installing capybara-webkit:
ERROR: Failed to build gem native extension.

/Users/joe/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb

Gem files will remain installed in /Users/joe/.rvm/gems/ruby-1.9.2-p290/gems/capybara-webkit-0.7.2 for inspection.
Results logged to /Users/joe/.rvm/gems/ruby-1.9.2-p290/gems/capybara-webkit-0.7.2/./gem_make.out

这是gem_make.out的结果

/Users/joe/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb

I am new to ruby, but while trying to install capybara to run test on my system I get the following error.Im running OSXhere are results from gem_make.out

问题:

由于此错误,我无法执行rails console :

localhost:TwitterForZombies wiz$ rails c
/Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `require': dlopen(/Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib (LoadError)
  Referenced from: /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle
  Reason: image not found - /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:3:in `require'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:38:in `require'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:38:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

我通过自制软件安装了readline。 我想继续使用rbenv而不是rvm。

感谢您阅读我的问题。

I cannot execute rails console due to this error:I have installed readline via homebrew.I’d like to keep using rbenv instead of rvm.Thank you for reading my question.

问题:

几个星期前Jekyll对我很好,但现在突然间它给了我以下错误:

TCPServer Error: Address already in use - bind(2)
INFO  WEBrick::HTTPServer#start: pid=7300 port=4000

 % lsof -i :4000
 <fetches nothing>

即使端口上没有运行任何东西。 以下是详细信息:

 % jekyll --version
Jekyll 0.11.2
 % where jekyll
/home/bhaarat/.rvm/gems/ruby-1.9.2-p290/bin/jekyll
/usr/bin/jekyll
 % ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
 % rvm --version
rvm 1.10.0 

这是输出

 % jekyll --server
Configuration from /home/bhaarat/blog/omnipresent.github.com/_config.yml
Auto-regenerating enabled: /home/bhaarat/blog/omnipresent.github.com -> /home/bhaarat/blog/omnipresent.github.com/_site
[2012-04-21 13:46:40] regeneration: 38 files changed
[2012-04-21 13:46:40] INFO  WEBrick 1.3.1
[2012-04-21 13:46:40] INFO  ruby 1.9.2 (2011-07-09) [i686-linux]
[2012-04-21 13:46:40] WARN  TCPServer Error: Address already in use - bind(2)
[2012-04-21 13:46:40] INFO  WEBrick::HTTPServer#start: pid=7382 port=4000

我知道地址没有被使用,jekyll可能因为其他原因而破坏但是抛出了这个错误。 我有什么选择? 我也尝试过重新安装。

Jekyll was working fine for me few weeks back but now all of a sudden it gives me the following error:Even though nothing is running on the port.Below are the details:Here is the outputI know the address isn’t in use and jekyll is probably breaking for some other reason but throwing that error.What are my options?I’ve tried re-installing as well.

问题:

我似乎无法找到有关自定义异常类的更多信息。

我所知道的

您可以声明自定义错误类并让它继承自StandardError ,因此可以进行rescue d:

class MyCustomError < StandardError
end

这允许您使用以下方法来提高它:

raise MyCustomError, "A message"

然后,在救援时获取该消息

rescue MyCustomError => e
  puts e.message # => "A message"

我不知道的

我想给我的异常一些自定义字段,但我想从父类继承message属性。 我发现在这个主题上读到@message不是异常类的实例变量,所以我担心我的继承不起作用。

谁能给我更多细节呢? 如何使用object属性实现自定义错误类? 以下是正确的:

class MyCustomError < StandardError
  attr_reader :object
  def initialize(message, object)
    super(message)
    @object = object
  end
end

然后:

raise MyCustomError.new(anObject), "A message"

要得到:

rescue MyCustomError => e
  puts e.message # => "A message"
  puts e.object # => anObject

它会起作用,如果确实如此,这是正确的做事方式吗?

I can’t seem to find much information about custom exception classes.What I do knowYou can declare your custom error class and let it inherit from StandardError , so it can be rescue d:This allows you to raise it using:and later, get that message when rescuingWhat I don’t knowI want to give my exception some custom fields, but I want to inherit the message attribute from the parent class.I found out reading on this topic that @message is not an instance variable of the exception class, so I’m worried that my inheritance won’t work.Can anyone give me more details to this?How would I implement a custom error class with an object attribute?Is the following correct:And then:to get:will it work, and if it does, is this the correct way of doing things?

问题:

我有一些代码需要挽救ruby中的多种类型的异常:

begin
  a = rand
  if a > 0.5
    raise FooException
  else
    raise BarException
  end
rescue FooException, BarException
  puts "rescued!"
end

我想做的是以某种方式将要抢救的异常类型列表存储在某个地方,然后将这些类型传递给抢救子句:

EXCEPTIONS = [FooException, BarException]

接着:

rescue EXCEPTIONS

这是否有可能,而且如果没有对eval真正的恶意调用,是否有可能? 考虑到我尝试上述操作时看到的是TypeError: class or module required for rescue clause ,因此我不抱希望。

I have some code that needs to rescue multiple types of exceptions in ruby:What I’d like to do is somehow store the list of exception types that I want to rescue somewhere and pass those types to the rescue clause:and then:Is this even possible, and is it possible without some really hack-y calls to eval ?I’m not hopeful given that I’m seeing TypeError: class or module required for rescue clause when I attempt the above.