1

In Clojure it's possible to evalute a form inline and get the result printed. The implementations vary for different editors, but here's how it looks like using Visual Studio Code with Calva:

enter image description here

Is it possible in any editor to do the same (or something similar) with Ruby?

Alexander Popov
  • 23,073
  • 19
  • 91
  • 130

2 Answers2

2

In a sense this is trivially possible in any editor with plugin/scripting capabilities. It's just a question of how much work you're willing to put in.

For example, this blog describes how to do it in Vim. The specific method is not really important, the point is that it's possible because of the features that Vim has:

  • it has scripting, so you can read/write to variables and string together operations
  • it can evaluate arbitrary system commands
  • it has customizable key bindings

So it can basically automate what you would do manually: copy some source code, paste that code into the interpreter, run it, capture the result as text, paste it back in the editor.

Max
  • 21,123
  • 5
  • 49
  • 71
1

I suppose this feature is very common for functional languages (at least Elm, Haskell supports this, too) but I don't think it's possible in Ruby. But you can use REPL (eg. IRB or Pry) to get the return value of the statement you typed after pressing enter key.

If there is an IDE Extension that supports this feature I'm very eager to hear about it.

StandardNerd
  • 4,093
  • 9
  • 46
  • 77