Permalink
Browse files

add bang variations of *methods to show locations

  • Loading branch information...
1 parent b7d6454 commit 8da73b0f16c75e173811b724ef9dbf6b537bce98 @sunaku committed Sep 6, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 .irbrc
View
20 .irbrc
@@ -45,3 +45,23 @@ IRB.conf[:AUTO_INDENT] = true
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 10_000
+
+#-----------------------------------------------------------------------------
+# utility
+#-----------------------------------------------------------------------------
+
+class Object
+ # create bang methods to reveal method origins
+ methods.grep(/methods$/).each do |plural|
+ singular = plural.to_s.sub(/s$/, '').to_sym
+ singular = :method unless respond_to? singular
+ define_method "#{plural}!" do |*args|
+ Hash[
+ send(plural, *args).map do |name|
+ method = send(singular, name)
+ [method, method.source_location]
+ end
+ ]
+ end
+ end
+end

0 comments on commit 8da73b0

Please sign in to comment.