Created
June 4, 2013 13:55
-
-
Save oelmekki/5706109 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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