inch-ci / inch_ci-web

Web frontend for Inch CI
http://inch-ci.org/
MIT License
139 stars 20 forks source link

Module Method Detected as Both Module and Instance Method #61

Open fny opened 9 years ago

fny commented 9 years ago

The module method Interrobang.bangify_method was improperly detected as both a module and instance method.


Re: [B] Interrobang#bangify_method in fny/interrobang

rrrene commented 9 years ago

Since you are using module_function, you are creating both an instance and a module function. See Ruby's docs:

Creates module functions for the named methods. These functions may be called with the module as a receiver, and also become available as instance methods to classes that mix in the module. Module functions are copies of the original, and so may be changed independently.

So I am afraid I cannot do anything about this behaviour ...

fny commented 9 years ago

This I know, but you could be clever about it:

module Hello
  module_function
  def hello
  end
end

hello1 = Hello.method(:hello)
hello2 = Hello.instance_method(:hello)

hello1.source_location # => [ '/somewhere/hello.rb', 3 ]
hello2.source_location # => [ '/somewhere/hello.rb', 3 ]
rrrene commented 9 years ago

Mmmh, good point :wink: