What does "Previous definition of x was here" in Ruby mean?

时间:2018-03-09 19:02:36

标签: ruby

In my Sinatra/activerecord app, rake test gives me this odd series of warnings:

/Users/pitosalas/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/activesupport-5.1.5/lib/active_support/core_ext/hash/slice.rb:21: warning: method redefined; discarding old slice
/Users/pitosalas/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/arel-8.0.0/lib/arel/visitors/informix.rb:21: warning: assigned but unused variable - froms
/Users/pitosalas/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bunny-2.9.2/lib/bunny/cruby/ssl_socket.rb:110: warning: assigned but unused variable - le
/Users/pitosalas/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bunny-2.9.2/lib/bunny/session.rb:259: warning: method redefined; discarding old port
/Users/pitosalas/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bunny-2.9.2/lib/bunny/queue.rb:384: warning: method redefined; discarding old add_default_options
/Users/pitosalas/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bunny-2.9.2/lib/bunny/queue.rb:379: warning: previous definition of add_default_options was here
/Users/pitosalas/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bunny-2.9.2/lib/bunny/channel.rb:1580: warning: method redefined; discarding old to_s
/Users/pitosalas/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/bunny-2.9.2/lib/bunny/channel.rb:257: warning: previous definition of to_s was here

I am mainly interested in the messages like: warning: previous definition of to_s was here

What are they telling me? I can't find any clear reference to that message on line.

1 个答案:

答案 0 :(得分:1)

这实际上是一个两部分警告。

  

bunny-2.9.2 / lib / bunny / channel.rb:1580:警告:方法重新定义;丢弃旧的to_s

     

bunny-2.9.2 / lib / bunny / channel.rb:257:警告:to_s的先前定义在这里

它告诉您to_s为该课程定义了channel.rb:257,然后在to_s找到了同一班级channel.rb:1580的另一个定义。它通过使用channel.rb:1580处的模糊性来警告您模糊性及其解决方法。