0

I have two self-made separate gems, but both of them have a same function called foo for example, and foo is implemented in C, and it's under the same namespace, so is there a way to determine if I require both gems, which version of foo I use, or is it a way to make sure I'm actually using one of the gem's foo function, someone recommend to use cerr.

Though I know they're redundant, but so far I don't want to remove on of them due to some reasons.

hyaocuk
  • 1
  • 4
  • Can you please add more background? Please tell us, if you can, why the two gems use the same namespace, why you can't change them so that they don't, and why you can't remove one of them. – Wayne Conrad Feb 20 '14 at 12:10

1 Answers1

1

I searched "ruby programmatically find function definition", and found this answer: How can I get source code of a method dynamically and also which file is this method locate in.

This, plus some brief IRB experimentation leads me to believe that you want to do something like:

filename, lineno = method(:foo).source_location

if filename == "blah"
   puts "looks like :foo is defined in 'blah'"
elsif filename == "blargh"
   puts "looks like :foo is defined in 'blargh'"
end

Here is some more documentation for source_location: http://ruby-doc.org/core-1.9.3/Method.html#method-i-source_location

Community
  • 1
  • 1
Daniel Waltrip
  • 2,530
  • 4
  • 25
  • 30