Function: org-babel-ruby-evaluate

org-babel-ruby-evaluate is a byte-compiled function defined in ob-ruby.el.gz.

Signature

(org-babel-ruby-evaluate BUFFER BODY &optional RESULT-TYPE RESULT-PARAMS)

Documentation

Pass BODY to the Ruby process in BUFFER.

If RESULT-TYPE equals output then return a list of the outputs of the statements in BODY, if RESULT-TYPE equals value then return the value of the last statement in BODY, as elisp.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-ruby.el.gz
(defun org-babel-ruby-evaluate
    (buffer body &optional result-type result-params)
  "Pass BODY to the Ruby process in BUFFER.
If RESULT-TYPE equals `output' then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals `value' then
return the value of the last statement in BODY, as elisp."
  (if (not buffer)
      ;; external process evaluation
      (pcase result-type
	(`output (org-babel-eval org-babel-ruby-command body))
	(`value (let ((tmp-file (org-babel-temp-file "ruby-")))
		  (org-babel-eval
		   org-babel-ruby-command
		   (format (if (member "pp" result-params)
			       org-babel-ruby-pp-wrapper-method
			     org-babel-ruby-wrapper-method)
			   body (org-babel-process-file-name tmp-file 'noquote)))
		  (org-babel-eval-read-file tmp-file))))
    ;; comint session evaluation
    (pcase result-type
      (`output
       (let ((eoe-string (format "puts \"%s\"" org-babel-ruby-eoe-indicator)))
	 ;; Force the session to be ready before the actual session
	 ;; code is run.  There is some problem in comint that will
	 ;; sometimes show the prompt after the input has already
	 ;; been inserted and that throws off the extraction of the
	 ;; result for Babel.
	 (org-babel-comint-with-output
	     (buffer org-babel-ruby-eoe-indicator t eoe-string)
	   (insert eoe-string) (comint-send-input nil t))
	 ;; Now we can start the evaluation.
	 (mapconcat
	  #'identity
	  (butlast
	   (split-string
	    (mapconcat
	     #'org-trim
	     (org-babel-comint-with-output
		 (buffer org-babel-ruby-eoe-indicator t body)
	       (mapc
		(lambda (line)
		  (insert (org-babel-chomp line)) (comint-send-input nil t))
		(list "conf.echo=false;_org_prompt_mode=conf.prompt_mode;conf.prompt_mode=:NULL"
		      body
		      "conf.prompt_mode=_org_prompt_mode;conf.echo=true"
		      eoe-string)))
	     "\n") "[\r\n]") 4) "\n")))
      (`value
       (let* ((tmp-file (org-babel-temp-file "ruby-"))
	      (ppp (or (member "code" result-params)
		       (member "pp" result-params))))
	 (org-babel-comint-with-output
	     (buffer org-babel-ruby-eoe-indicator t body)
	   (when ppp (insert "require 'pp';") (comint-send-input nil t))
	   (mapc
	    (lambda (line)
	      (insert (org-babel-chomp line)) (comint-send-input nil t))
	    (append
	     (list body)
	     (if (not ppp)
		 (list (format org-babel-ruby-f-write
			       (org-babel-process-file-name tmp-file 'noquote)))
	       (list
		"results=_" "require 'pp'" "orig_out = $stdout"
		(format org-babel-ruby-pp-f-write
			(org-babel-process-file-name tmp-file 'noquote))))
	     (list org-babel-ruby-eoe-indicator)))
	   (comint-send-input nil t))
	 (org-babel-eval-read-file tmp-file))))))