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.



222
223
224
225
226
# File 'lib/looksee.rb', line 222

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

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



234
235
236
# File 'lib/looksee.rb', line 234

def methods
  @methods
end

#moduleObject (readonly)

Returns the value of attribute module.



234
235
236
# File 'lib/looksee.rb', line 234

def module
  @module
end

Class Method Details

.for(mod, seen, options) ⇒ Object



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

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).



273
274
275
276
277
# File 'lib/looksee.rb', line 273

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

#grep(pattern) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
# File 'lib/looksee.rb', line 244

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



236
237
238
239
240
241
242
# File 'lib/looksee.rb', line 236

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.



287
288
289
290
# File 'lib/looksee.rb', line 287

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?



263
264
265
266
267
# File 'lib/looksee.rb', line 263

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