Class: Looksee::LookupPath::Entry
- 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
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#module ⇒ Object
readonly
Returns the value of attribute module.
Class Method Summary collapse
Instance Method Summary collapse
-
#each ⇒ Object
Yield each method along with its visibility (:public, :private, :protected, :undefined, or :overridden).
- #grep(pattern) ⇒ Object
-
#initialize(mod, methods = [], visibilities = {}) ⇒ Entry
constructor
A new instance of Entry.
- #initialize_for(seen, options) ⇒ Object
-
#inspect(options = {}) ⇒ Object
Return a nice, pretty string for inspection.
-
#module_name ⇒ Object
Return the name of the class or module.
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
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
234 235 236 |
# File 'lib/looksee.rb', line 234 def methods @methods end |
#module ⇒ Object (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, ) entry = new(mod) entry.initialize_for(seen, ) entry end |
Instance Method Details
#each ⇒ Object
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, ) add_methods(Looksee.internal_public_instance_methods(@module).map{|sym| sym.to_s} , :public , seen) if [:public ] add_methods(Looksee.internal_protected_instance_methods(@module).map{|sym| sym.to_s}, :protected, seen) if [:protected] add_methods(Looksee.internal_private_instance_methods(@module).map{|sym| sym.to_s} , :private , seen) if [:private ] add_methods(Looksee.internal_undefined_instance_methods(@module).map{|sym| sym.to_s}, :undefined, seen) if [: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(={}) string = styled_module_name << "\n" << Columnizer.columnize(styled_methods, [:width]) string.chomp end |
#module_name ⇒ Object
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 |