Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Supercharged method introspection in IRB
C Ruby Java C++
branch: master
Failed to load latest commit information.
ext Ruby 2.2.0 support.
lib Bump to version 3.1.0.
spec Revert change to implement #ls via method_missing.
.autotest Hi.
.gitignore Gitignore .bundle.
.travis.yml See if we work with rbx 2.4.1.
CHANGELOG Bump to version 3.1.0.
Gemfile Pin rspec at 3.1.0.
History.txt Update history.
LICENSE Add LICENSE.
README.markdown Reorder README sections to flow better.
Rakefile Travis.
looksee.gemspec

README.markdown

Looksee Build Status Gem Version

A tool for illustrating the ancestry and method lookup path of objects. Handy for exploring unfamiliar codebases.

How

Install me:

gem install looksee

Pop this in your .irbrc:

require 'looksee'

Now each object has a method ls, which shows you all its methods.

irb> [].ls
=> BasicObject
  !       __send__       instance_exec             singleton_method_undefined
  !=      equal?         method_missing
  ==      initialize     singleton_method_added
  __id__  instance_eval  singleton_method_removed
Kernel
  !~                       frozen?                     puts
  <=>                      gem                         raise
  ===                      gem_original_require        rand
  =~                       gets                        readline
  Array                    global_variables            readlines
  Complex                  hash                        remove_instance_variable
  Float                    initialize_clone            require
  Integer                  initialize_copy             require_relative
  Rational                 initialize_dup              respond_to?
  String                   inspect                     respond_to_missing?
  __callee__               instance_of?                select
  __method__               instance_variable_defined?  send
  `                        instance_variable_get       set_trace_func
  abort                    instance_variable_set       singleton_class
  at_exit                  instance_variables          singleton_methods
  autoload                 is_a?                       sleep
  autoload?                iterator?                   spawn
  binding                  kind_of?                    sprintf
  block_given?             lambda                      srand
  caller                   load                        syscall
  catch                    local_variables             system
  class                    loop                        taint
  clone                    method                      tainted?
  define_singleton_method  methods                     tap
  display                  nil?                        test
  dup                      object_id                   throw
  enum_for                 open                        to_enum
  eql?                     p                           to_s
  eval                     print                       trace_var
  exec                     printf                      trap
  exit                     private_methods             trust
  exit!                    proc                        untaint
  extend                   protected_methods           untrace_var
  fail                     public_method               untrust
  fork                     public_methods              untrusted?
  format                   public_send                 warn
  freeze                   putc
Looksee::ObjectMixin
  ls
Object
  default_src_encoding  irb_binding
Enumerable
  all?            each_cons         flat_map  min_by        slice_before
  any?            each_entry        grep      minmax        sort
  chunk           each_slice        group_by  minmax_by     sort_by
  collect         each_with_index   include?  none?         take
  collect_concat  each_with_object  inject    one?          take_while
  count           entries           map       partition     to_a
  cycle           find              max       reduce        to_set
  detect          find_all          max_by    reject        zip
  drop            find_index        member?   reverse_each
  drop_while      first             min       select
Array
  &            count       hash             rassoc                size
  *            cycle       include?         reject                slice
  +            delete      index            reject!               slice!
  -            delete_at   initialize       repeated_combination  sort
  <<           delete_if   initialize_copy  repeated_permutation  sort!
  <=>          drop        insert           replace               sort_by!
  ==           drop_while  inspect          reverse               take
  []           each        join             reverse!              take_while
  []=          each_index  keep_if          reverse_each          to_a
  assoc        empty?      last             rindex                to_ary
  at           eql?        length           rotate                to_s
  clear        fetch       map              rotate!               transpose
  collect      fill        map!             sample                uniq
  collect!     find_index  pack             select                uniq!
  combination  first       permutation      select!               unshift
  compact      flatten     pop              shift                 values_at
  compact!     flatten!    product          shuffle               zip
  concat       frozen?     push             shuffle!              |

Methods are colored according to whether they're public, protected, private, undefined (using Module#undef_method), or overridden.

You can hide, say, private methods like this:

irb> [].ls :noprivate

Or filter the list by Regexp:

irb> [].ls /^to_/
 => BasicObject
Kernel
  to_enum  to_s
Looksee::ObjectMixin
Object
  to_yaml  to_yaml_properties  to_yaml_style
Enumerable
  to_a  to_set
Array
  to_a  to_ary  to_s  to_yaml

Proxy objects

Objects that delegate everything via method_missing to some other object can be tricky, because they will delegate ls itself. To view such objects, you can always do:

Looksee[object]

This method inspects the object via interpreter extensions, so it works for the most Byzantine object. It will also work for BasicObject instances that don't have an ls method. Object#ls is simply a wrapper around Looksee.[].

To the source!

If you want to know more about any of those methods, Looksee can take you straight to the source in your editor:

[].ls.edit :to_set

By default, this uses vi; customize it like this:

# %f = file, %l = line number
Looksee.editor = "mate -l%l %f"

ls in your way?

If you have a library that for some reason can't handle an ls method existing on Object, you may rename it like this:

Looksee.rename ls: :_ls

Quick Reference

We've got one:

Looksee.help

Enjoy!

Support

Looksee supports:

  • MRI 1.9.3, 2.0, 2.1, 2.2
  • JRuby 1.7
  • Rubinius 2.4

Contributing

  • Bug reports
  • Source
  • Patches: Fork on Github, send pull request.
    • Include tests where practical.
    • Leave the version alone, or bump it in a separate commit.

Copyright

Copyright (c) George Ogata. See LICENSE for details.

Something went wrong with that request. Please try again.