I heard that vim is the editor that Rubyists use. I wanted to find out how to execute a script from within the vim editor. Because I use RVM (ruby version manager), the usual !# (sha-bang) did not work but with a slight alteration, all ended well.
At the terminal command line, I switched to my Ruby of choice using RVM and then started vim to begin editing Sample.rb.
[ruby] rvm use 1.9.3 Using /Users/javapro/.rvm/gems/ruby-1.9.3-preview1 [ruby] vim Sample.rb
#!/usr/bin/env ruby class Sample def hello puts "Hello, World" end end s = Sample.new s.hello
Now, to run Sample.rb from within the vim editing session, press escape colon bang space percent enter. The vim editor will appear as below just before enter is pressed.
#!/usr/bin/env ruby class Sample def hello puts "Hello, World" end end s = Sample.new s.hello ~ ~ ~ ~ :! %
Hello, World Press ENTER or type command to continue