Skip to content

Instantly share code, notes, and snippets.

@jxa
Created January 2, 2012 17:57
Show Gist options
  • Save jxa/1551540 to your computer and use it in GitHub Desktop.
Save jxa/1551540 to your computer and use it in GitHub Desktop.
REPL tools for looking up docs and listing an object's methods. Put this file in ~/.lein
(use 'clojure.repl)
(use 'clojure.java.javadoc)
(use '[clojure.reflect :only [reflect]])
(use '[clojure.string :only [join]])
(defn inspect [obj]
"nicer output for reflecting on an object's methods"
(let [reflection (reflect obj)
members (sort-by :name (:members reflection))]
(println "Class:" (.getClass obj))
(println "Bases:" (:bases reflection))
(println "---------------------\nConstructors:")
(doseq [constructor (filter #(instance? clojure.reflect.Constructor %) members)]
(println (:name constructor) "(" (join ", " (:parameter-types constructor)) ")"))
(println "---------------------\nMethods:")
(doseq [method (filter #(instance? clojure.reflect.Method %) members)]
(println (:name method) "(" (join ", " (:parameter-types method)) ") ;=>" (:return-type method)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment