Class: UnboundMethod
- Inherits:
-
Object
- Object
- UnboundMethod
- Defined in:
- lib/bently/core_ext/method.rb
Instance Method Summary collapse
-
#source_location ⇒ Array
Return the source location of an instance method for Ruby 1.8.
Instance Method Details
#source_location ⇒ Array
Return the source location of an instance method for Ruby 1.8.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bently/core_ext/method.rb', line 60 def source_location klass = case owner when Class owner when Module method_owner = owner Class.new { include(method_owner) } end # deal with immediate values case when klass == Symbol return :a.method(name).source_location when klass == Fixnum return 0.method(name).source_location when klass == TrueClass return true.method(name).source_location when klass == FalseClass return false.method(name).source_location when klass == NilClass return nil.method(name).source_location end begin Object.instance_method(:method).bind(klass.allocate).call(name).source_location rescue TypeError # Assume we are dealing with a Singleton Class: # 1. Get the instance object # 2. Forward the source_location lookup to the instance instance ||= ObjectSpace.each_object(owner).first Object.instance_method(:method).bind(instance).call(name).source_location end end |