Skip to content

Instantly share code, notes, and snippets.

@inem
Forked from nex3/to_sh.rb
Created February 10, 2010 06:37
Show Gist options
  • Save inem/300084 to your computer and use it in GitHub Desktop.
Save inem/300084 to your computer and use it in GitHub Desktop.
require 'parse_tree'
require 'ruby2ruby'
require 'parse_tree_extensions'
require 'shellwords'
class Proc
def to_sh
ruby = `which ruby`.strip
command = Shellwords.shellescape(to_ruby.gsub(/\Aproc \{(.*)\}\Z/m, '\1').strip)
paths = $LOAD_PATH.map {|p| Shellwords.shellescape("-I" + p)}.join(" ")
requires = $LOADED_FEATURES.reverse.map {|p| Shellwords.shellescape("-r" + p)}.join(" ")
"#{ruby} #{paths} #{requires} -e #{command}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment