如果我遵循this article的以下部分:
Figure out where a method was defined
object = Object.new
puts object.method(:blank?).source_location
=> ["/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/object/blank.rb", 14]
我应该能够找到blank?
方法的定义,但是当我在irb
中使用ruby 2.0.0
尝试此代码时,我收到以下错误消息:
➜ ~ irb
irb(main):001:0> object = Object.new
=> #<Object:0x007fc84882f088>
irb(main):002:0> puts object.method(:blank?).source_location
NameError: undefined method `blank?' for class `Object'
from (irb):2:in `method'
from (irb):2
from /usr/bin/irb:12:in `<main>'
我错过了什么吗?
谢谢。
答案 0 :(得分:1)
.blank?
类型不存在 Object
方法。如果我包含String
lib
active_support
方法
irb(main):001:0> String.new.method(:blank?).source_location
=> ["/home/xeon/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object/blank.rb", 116]
如果您添加activesupport-5.0.0.beta1
,那么它将适合您。 (查看您发布的文章的源路径)