Skip to content

Instantly share code, notes, and snippets.

@jsborjesson
Last active August 29, 2015 14:01
Show Gist options
  • Save jsborjesson/922904852bb5a470b7aa to your computer and use it in GitHub Desktop.
Save jsborjesson/922904852bb5a470b7aa to your computer and use it in GitHub Desktop.
Execute selected ruby into inline comments
" Inline ruby interpretation, inspired by RubyTapas.
"
" Example output when run over the top line:
"
" 3.times { |num| puts num }
" # => 0
" # => 1
" # => 2
"
vmap <leader>r :!tee >(cat) \| ruby \| sed 's/^/\\# \=> /'<cr>
@jsborjesson
Copy link
Author

Broken down:

  • tee pipes to two commands, the first is cat that just repeats what it gets to not replace the original code
  • ruby outputs the result when things are piped to it
  • sed puts the comments in front of the result, with some wonky escaping

@jsborjesson
Copy link
Author

This is basically a poor man's seeing is believing in one line. Obviously much worse but still cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment