Class: Looksee::LookupPath

Inherits:
Object
  • Object
show all
Defined in:
lib/looksee/lookup_path.rb

Overview

Represents the method lookup path of an object, as a list of Entries.

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ LookupPath

Returns a new instance of LookupPath.



7
8
9
10
# File 'lib/looksee/lookup_path.rb', line 7

def initialize(object)
  @object = object
  @entries = create_entries
end

Instance Attribute Details

#entriesObject (readonly)

List of Entry objects, each one representing a Module in the lookup path.



21
22
23
# File 'lib/looksee/lookup_path.rb', line 21

def entries
  @entries
end

#objectObject (readonly)

The object this lookup path represents.



15
16
17
# File 'lib/looksee/lookup_path.rb', line 15

def object
  @object
end

Instance Method Details

#find(name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/looksee/lookup_path.rb', line 23

def find(name)
  entries.each do |entry|
    visibility = entry.methods[name] or
      next

    if visibility == :undefined
      return nil
    else
      return Looksee.safe_call(Module, :instance_method, entry.module, name)
    end
  end
  nil
end

#inspect(options = {}) ⇒ Object

Return a string showing the object’s lookup path.



40
41
42
# File 'lib/looksee/lookup_path.rb', line 40

def inspect(options={})
  Inspector.new(self, options).inspect
end