简体   繁体   中英

Is it possible to get inline evaluation similar to Clojure in Ruby?

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:

在此处输入图片说明

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

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.

Yes!

This tool integrates with a bunch of editors.

Avdi Grimm the author of Ruby Tapas screencasts uses it a lot. Example

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM