Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created June 4, 2013 13:55
Show Gist options
  • Save oelmekki/5706109 to your computer and use it in GitHub Desktop.
Save oelmekki/5706109 to your computer and use it in GitHub Desktop.
class Object
# Display an object methods list with their source location.
#
# @param [Regexp] method_pattern grep method name
# @param [Regexp] file_pattern grep file name
def located_methods( method_pattern = nil, file_pattern = nil )
list = ( method_pattern ? methods.grep( method_pattern ) : methods ).sort.map do |name|
location = method( name ).source_location
location = "#{location.first} line #{location.second}" if location
[ name.to_s.colorize( :yellow ), location ]
end
list = list.select { |meth| meth[1] =~ file_pattern } if file_pattern
puts ( [[ 'Name'.colorize( :yellow ), 'Location' ]] + list ).to_table( first_row_is_head: true )
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment