ethd
ethd

Reputation: 183

Figure out where a method was defined

If I follow the following part of 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]

I should be able to find the definition of the blank? method, however when I try this code within irb with ruby 2.0.0 I get this error message:

    ➜  ~ 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>'

Did I miss anything?

Thank you.

Upvotes: 0

Views: 48

Answers (1)

a131
a131

Reputation: 564

.blank? method does not exist for a Object type. I know for sure it exists for a String method if I include the active_support lib

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]

If you include activesupport-5.0.0.beta1 then it will work for you. (Looking at the source path of the article you have posted)

Upvotes: 1

Related Questions