Skip to content

Instantly share code, notes, and snippets.

@moro
Created September 28, 2010 02:09
Show Gist options
  • Save moro/600281 to your computer and use it in GitHub Desktop.
Save moro/600281 to your computer and use it in GitHub Desktop.
class TapTree
module Adapter
def taptree(n = nil, filter = nil)
tap{|x| TapTree.new(x, filter).display(n) }
end
end
IGNORE = [TapTree::Adapter]
COLS = 100
def initialize(obj, filter_re = nil)
@obj = obj
@filter_re = filter_re
end
def display(n = nil)
if @obj.is_a?(Module)
limit(@obj.ancestors, n).each do |klass|
puts klass.to_s + '(%s)' % klass.class
display_methods(klass.singleton_methods(false))
end
else
limit(@obj.class.ancestors, n).each do |klass|
puts klass.to_s + '#'
display_methods(klass.public_instance_methods(false))
end
end
end
private
def limit(ancestors, n)
as = ancestors.reject{|a| IGNORE.include?(a) }
n.nil? ? as : as[0, n]
end
def display_methods(methods)
alpha, op = methods.sort.partition{|m| m =~ /\A[_A-Za-z]/o }
display_each_methods(alpha, COLS)
display_each_methods(op, COLS)
puts 'v' + '-' * (COLS - 1)
end
def display_each_methods(methods, cols)
buf = '| '
methods.each do |m|
next if @filter_re && @filter_re !~ m
if (buf + m).length > cols
puts buf.sub(/\,\s*\Z/, '')
buf = '| ' + m + ', '
else
buf << m << ', '
end
end
puts buf.sub(/\,\s*\Z/, '') unless buf == '| '
end
end
Object.send(:include, TapTree::Adapter)
if __FILE__ == $0
%w[a b c].taptree
puts
1.taptree
puts
require 'rubygems'
require 'active_record'
ActiveRecord::Base.taptree(1, /sql/)
end
@moro
Copy link
Author

moro commented Sep 28, 2010

Array#
| assoc, at, choice, clear, collect, collect!, combination, compact, compact!, concat, count, cycle
| delete, delete_at, delete_if, drop, drop_while, each, each_index, empty?, eql?, fetch, fill
| find_index, first, flatten, flatten!, frozen?, hash, include?, index, indexes, indices, insert
| inspect, join, last, length, map, map!, nitems, pack, permutation, pop, product, push, rassoc
| reject, reject!, replace, reverse, reverse!, reverse_each, rindex, select, shift, shuffle
| shuffle!, size, slice, slice!, sort, sort!, take, take_while, to_a, to_ary, to_s, transpose, uniq
| uniq!, unshift, values_at, zip
| &, *, +, -, <<, <=>, ==, [], []=, |
v---------------------------------------------------------------------------------------------------
Enumerable#
| all?, any?, collect, count, cycle, detect, drop, drop_while, each_cons, each_slice
| each_with_index, entries, enum_cons, enum_slice, enum_with_index, find, find_all, find_index
| first, grep, group_by, include?, inject, map, max, max_by, member?, min, min_by, minmax, minmax_by
| none?, one?, partition, reduce, reject, reverse_each, select, sort, sort_by, take, take_while
| to_a, zip
v---------------------------------------------------------------------------------------------------
Object#
v---------------------------------------------------------------------------------------------------
Kernel#
| __id__, __send__, class, clone, display, dup, enum_for, eql?, equal?, extend, freeze, frozen?
| hash, id, inspect, instance_eval, instance_exec, instance_of?, instance_variable_defined?
| instance_variable_get, instance_variable_set, instance_variables, is_a?, kind_of?, method, methods
| nil?, object_id, private_methods, protected_methods, public_methods, respond_to?, send
| singleton_methods, taint, tainted?, tap, to_a, to_enum, to_s, type, untaint
| ==, ===, =~
v---------------------------------------------------------------------------------------------------

Fixnum#
| abs, div, divmod, even?, fdiv, id2name, modulo, odd?, quo, size, to_f, to_s, to_sym, zero?
| %, &, *, **, +, -, -@, /, <, <<, <=, <=>, ==, >, >=, >>, [], ^, |, ~
v---------------------------------------------------------------------------------------------------
Integer#
| ceil, chr, downto, even?, floor, integer?, next, odd?, ord, pred, round, succ, times, to_i, to_int
| truncate, upto
v---------------------------------------------------------------------------------------------------
Precision#
| prec, prec_f, prec_i
v---------------------------------------------------------------------------------------------------
Numeric#
| abs, ceil, coerce, div, divmod, eql?, fdiv, floor, integer?, modulo, nonzero?, quo, remainder
| round, singleton_method_added, step, to_int, truncate, zero?
| +@, -@, <=>
v---------------------------------------------------------------------------------------------------
Comparable#
| between?
| <, <=, ==, >, >=
v---------------------------------------------------------------------------------------------------
Object#
v---------------------------------------------------------------------------------------------------
Kernel#
| __id__, __send__, class, clone, display, dup, enum_for, eql?, equal?, extend, freeze, frozen?
| hash, id, inspect, instance_eval, instance_exec, instance_of?, instance_variable_defined?
| instance_variable_get, instance_variable_set, instance_variables, is_a?, kind_of?, method, methods
| nil?, object_id, private_methods, protected_methods, public_methods, respond_to?, send
| singleton_methods, taint, tainted?, tap, to_a, to_enum, to_s, type, untaint
| ==, ===, =~
v---------------------------------------------------------------------------------------------------

ActiveRecord::Base(Class)
| count_by_sql, find_by_sql, sanitize_sql, sanitize_sql_array, sanitize_sql_for_assignment
| sanitize_sql_for_conditions, sanitize_sql_hash, sanitize_sql_hash_for_assignment
| sanitize_sql_hash_for_conditions
v---------------------------------------------------------------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment