Class: Looksee::LookupPath::Entry

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

Overview

An entry in the LookupPath.

Contains a module and its methods, along with visibility information (public, private, etc.).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod, methods = [], visibilities = {}) ⇒ Entry

Returns a new instance of Entry.



218
219
220
221
222
# File 'lib/looksee.rb', line 218

def initialize(mod, methods=[], visibilities={})
  @module = mod
  @methods = methods
  @visibilities = visibilities
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



230
231
232
# File 'lib/looksee.rb', line 230

def methods
  @methods
end

#moduleObject (readonly)

Returns the value of attribute module.



230
231
232
# File 'lib/looksee.rb', line 230

def module
  @module
end

Class Method Details

.for(mod, seen, options) ⇒ Object



224
225
226
227
228
# File 'lib/looksee.rb', line 224

def self.for(mod, seen, options)
  entry = new(mod)
  entry.initialize_for(seen, options)
  entry
end

Instance Method Details

#eachObject

Yield each method along with its visibility (:public, :private, :protected, :undefined, or :overridden).



269
270
271
272
273
# File 'lib/looksee.rb', line 269

def each
  @methods.each do |name|
    yield name, @visibilities[name]
  end
end

#grep(pattern) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/looksee.rb', line 240

def grep(pattern)
  methods = []
  visibilities = {}
  @methods.each do |name|
    if name[pattern]
      methods << name
      visibilities[name] = @visibilities[name]
    end
  end
  self.class.new(@module, methods, visibilities)
end

#initialize_for(seen, options) ⇒ Object



232
233
234
235
236
237
238
# File 'lib/looksee.rb', line 232

def initialize_for(seen, options)
  add_methods(Looksee.internal_public_instance_methods(@module).map{|sym| sym.to_s}   , :public   , seen) if options[:public   ]
  add_methods(Looksee.internal_protected_instance_methods(@module).map{|sym| sym.to_s}, :protected, seen) if options[:protected]
  add_methods(Looksee.internal_private_instance_methods(@module).map{|sym| sym.to_s}  , :private  , seen) if options[:private  ]
  add_methods(Looksee.internal_undefined_instance_methods(@module).map{|sym| sym.to_s}, :undefined, seen) if options[:undefined]
  @methods.sort!
end

#inspect(options = {}) ⇒ Object

Return a nice, pretty string for inspection.

Contains the module name, plus the method names laid out in columns. Pass a :width option to control the output width.



283
284
285
286
# File 'lib/looksee.rb', line 283

def inspect(options={})
  string = styled_module_name << "\n" << Columnizer.columnize(styled_methods, options[:width])
  string.chomp
end

#module_nameObject

Return the name of the class or module.

Singleton classes are displayed in brackets. Singleton class of singleton classes are displayed in double brackets. But you’d never need that, would you?



259
260
261
262
263
# File 'lib/looksee.rb', line 259

def module_name
  name = @module.to_s  # #name doesn't do singleton classes right
  nil while name.sub!(/#<Class:(.*)>/, '[\\1]')
  name
end