Module: Looksee

Defined in:
lib/looksee/help.rb,
lib/looksee/clean.rb,
lib/looksee/editor.rb,
lib/looksee/adapter.rb,
lib/looksee/version.rb,
lib/looksee/core_ext.rb,
lib/looksee/inspector.rb,
lib/looksee/columnizer.rb,
lib/looksee/lookup_path.rb,
lib/looksee/adapter/base.rb,
lib/looksee/pretty_print_hack.rb

Defined Under Namespace

Modules: Adapter, Columnizer, ObjectMixin, PrettyPrintHack Classes: Editor, Help, Inspector, LookupPath

Constant Summary collapse

Config =
Object.const_defined?(:RbConfig) ? ::RbConfig : ::Config
NoMethodError =
Class.new(RuntimeError)
NoSourceLocationError =
Class.new(RuntimeError)
NoSourceFileError =
Class.new(RuntimeError)
VERSION =
[5, 1, 0]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.adapterObject

The interpreter adapter.

Encapsulates the interpreter-specific functionality.



86
87
88
# File 'lib/looksee/clean.rb', line 86

def adapter
  @adapter
end

.default_specifiersObject

The default options passed to #look.

Default: [:public, :protected, :private, :undefined, :overridden]



27
28
29
# File 'lib/looksee/clean.rb', line 27

def default_specifiers
  @default_specifiers
end

.default_widthObject

The width to use for displaying output, when not available in the COLUMNS environment variable.

Default: 80



35
36
37
# File 'lib/looksee/clean.rb', line 35

def default_width
  @default_width
end

.editorObject

The editor command, used for Object#edit.

This string should contain a “%f”, which is replaced with the file name, and/or “%l” which is replaced with the line number. A “%%” is replaced with “%”.

If the LOOKSEE_EDITOR environment variable is set, it is used as the default. Otherwise, we use the following heuristic:

If EDITOR is set, we use that. If it looks like vi, emacs, or textmate, we also append options to position the cursor on the appropriate line. If EDITOR is not set, we use “vi +%l %f”.



79
80
81
# File 'lib/looksee/clean.rb', line 79

def editor
  @editor
end

.ruby_engineObject

Wrapper around RUBY_ENGINE that’s always defined.



91
92
93
# File 'lib/looksee/clean.rb', line 91

def ruby_engine
  @ruby_engine
end

.stylesObject

The default styles to use for the inspect strings.

This is a hash with keys:

  • :module

  • :public

  • :protected

  • :private

  • :undefined

  • :overridden

The values are format strings. They should all contain a single “%s”, which is where the name is inserted.

Default:

{
  :module     => "\e[1;37m%s\e[0m", # white
  :public     => "\e[1;32m%s\e[0m", # green
  :protected  => "\e[1;33m%s\e[0m", # yellow
  :private    => "\e[1;31m%s\e[0m", # red
  :undefined  => "\e[1;34m%s\e[0m", # blue
  :overridden => "\e[1;30m%s\e[0m", # black
}


63
64
65
# File 'lib/looksee/clean.rb', line 63

def styles
  @styles
end

Class Method Details

.[](object, *args) ⇒ Object

Return a Looksee::Inspector for the given object.

args is an optional list of specifiers.

* +:public+ - include public methods
* +:protected+ - include public methods
* +:private+ - include public methods
* +:undefined+ - include public methods (see Module#undef_method)
* +:overridden+ - include public methods
* +:nopublic+ - include public methods
* +:noprotected+ - include public methods
* +:noprivate+ - include public methods
* +:noundefined+ - include public methods (see Module#undef_method)
* +:nooverridden+ - include public methods
* a string - only include methods containing this string (may
  be used multiple times)
* a regexp - only include methods matching this regexp (may
  be used multiple times)

The default (if options is nil or omitted) is given by #default_lookup_path_options.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/looksee/clean.rb', line 116

def [](object, *args)
  options = {:visibilities => Set[], :filters => Set[]}
  (Looksee.default_specifiers + args).each do |arg|
    case arg
    when String, Regexp
      options[:filters] << arg
    when :public, :protected, :private, :undefined, :overridden
      options[:visibilities].add(arg)
    when :nopublic, :noprotected, :noprivate, :noundefined, :nooverridden
      visibility = arg.to_s.sub(/\Ano/, '').to_sym
      options[:visibilities].delete(visibility)
    else
      raise ArgumentError, "invalid specifier: #{arg.inspect}"
    end
  end
  lookup_path = LookupPath.new(object)
  Inspector.new(lookup_path, options)
end

.helpObject

Show a quick reference.



138
139
140
# File 'lib/looksee/clean.rb', line 138

def help
  Help.new
end

.rename(name) ⇒ Object

Rename the #look method, added to every object. Example:

rename :_look

This renames Looksee’s #look method to #_look.

For backward compatibility, the old-style invocation is also supported. This is deprecated, and will shortly be removed.

rename :look => :_look


41
42
43
# File 'lib/looksee/core_ext.rb', line 41

def self.rename(name)
  ObjectMixin.rename(name)
end

.safe_call(mod, name, receiver, *args) ⇒ Object

Call mod#method on receiver, ignoring any overrides in receiver’s class.



143
144
145
# File 'lib/looksee/clean.rb', line 143

def safe_call(mod, name, receiver, *args) # :nodoc:
  mod.instance_method(name).bind(receiver).call(*args)
end