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.
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
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
230 231 232 |
# File 'lib/looksee.rb', line 230 def methods @methods end |
#module ⇒ Object (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, ) 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).
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, ) 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.
283 284 285 286 |
# File 'lib/looksee.rb', line 283 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?
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 |