How can I run a ruby piece of code from a buffer, without actually saving the buffer in a file? A scenario would be to
a) switch to the scratch buffer
b) M-x ruby-mode
c) type ruby code
d) “compile” the buffer and print results in another buffer. I don’t want to save the buffer contents in a file and then “compile” that file
UPDATE 1-9-2011
Which are the latest versions of ruby-mode and inf-ruby and where can I get them? I use the ubuntu natty version of ruby mode and the elpa version of inf-ruby of emacs 23.2. On a clean emacs config, the following config (see underneath) fail with:
can't convert nil into String from (irb):1:in `eval' from (irb):1".
Configuration is just the following, no other configuration directives in emacs.d:
(require 'ruby-mode) (load-file "Configs/.emacs.d/elpa/inf-ruby-2.1/inf-ruby.el") (autoload 'inf-ruby "inf-ruby" "Run an inferior Ruby pathrocess" t) (autoload 'inf-ruby-keys "inf-ruby" "" t) (eval-after-load 'ruby-mode '(add-hook 'ruby-mode-hook 'inf-ruby-keys))
You can do this with
inf-ruby.el.With
inf-rubyinstalled,M-x inf-rubystarts a new ruby interpreter in the background, to which you can send code using theruby-send-*commands, such asruby-send-region(bound by default toC-c C-r). To send the whole buffer, select all withC-x hthen hitC-c C-r.Update, 2011-09-02: The latest version of
inf-ruby.el(2.1.1, available in ELPA) is that maintained by ‘nonsequitur’ on github, and snapshot packages are available in Melpa.