           (comma-separate (map -emit args))))
 
 (defmethod -emit :if [{:keys [test then else] :as ast}]
-  (format "if %s\n%s\nelse\n%s\nend"
-          (-emit test)
-          (-emit then)
-          (-emit else)))
+  (let [else-expr (-emit else)]
+    (if (= "" else-expr)
+      (format "if %s\n%s\nend"
+              (-emit test)
+              (indent (-emit then)))
+      (format "if %s\n%s\nelse\n%s\nend"
+              (-emit test)
+              (indent (-emit then))
+              (indent else-expr)))))
 
 (defmethod -emit :do [{:keys [statements ret env] :as ast}]
   (endl-separate (map -emit (conj (vec statements) ret))))


(defn- wrap-quotes [s]
  (format "\"%s\"" s))

(defn- endl-separate [exprs]
  (clojure.string/join "\n" exprs))

(defn- module-eval [ns body]
  (if (and ns (not= 'user ns) (not= "" body))
    (format "%s.module_eval do\n%s\nend"
            (namespace->module (name ns))
            body)
    body))

(defmulti -emit (fn [{:keys [op] :as ast}] op))


  (format "%s.const_set(\"%s\", Class.new do\n%s\nend.new)"
          (namespace->module (name (:ns env)))
          (clojure.string/upper-case (name (gensym "fn")))
          (indent
            (format "def invoke(*args)\n%s\nend"
                    (indent (-emit (first methods)))))))

(defmethod -emit :local [{:keys [name] :as ast}]
  (str name))
