How to compile Ruby?
The simple answer is that you can't, at least with MRI 1.8 (the standard). This is because 1.8 works by walking the Abstract Syntax Tree. Python, Ruby 1.9, JRuby, and Rubinius use byte code, which allows compilation to an Intermediate Representation (byte code). From MRI Ruby 2.3 it has become easy to do this, see this answer below.
With Rubinius, you can do something as described in this post: http://rubini.us/2011/03/17/running-ruby-with-no-ruby/
In JRuby you can use the "Ahead Of Time" compiler through, I believe, jrubyc.
This isn't really the standard way of doing things and you're generally better off just letting your Ruby implementation handle it like it wants to. Rubinius, at least, will cache byte code after the first compilation, updating it as it needs to.
how to compile a ruby code on my vim-editor for very simple and easy way... or some trick
You can use :!!
to repeat the last :!{cmd}
.
You can type :!ruby %
once, and then run :!!
, which can of course be mapped to a key like:
nnoremap <F8> :!!<CR>
Or to write and run it (saves typing :w
):
nnoremap <F8> :w<CR>:!!<CR>
This is a flexible solution, since you can replace :!ruby %
with anything else (e.g. :!coffee -c %
, :!python %
, etc.).
How to compile ruby with RVM on a low memory system?
Creating a 512MB swap-file solved the problem. Here are the steps:
sudo mkdir -p /var/cache/swap/
sudo dd if=/dev/zero of=/var/cache/swap/swap0 bs=1M count=512
sudo chmod 0600 /var/cache/swap/swap0
sudo mkswap /var/cache/swap/swap0
sudo swapon /var/cache/swap/swap0
The swap file is not used after a restart. It can be integrated in /etc/fstab
to use it after restart:
/var/cache/swap/swap0 none swap sw 0 0
The above steps to create a swap-file I found here (in German): http://wiki.ubuntuusers.de/Swap#Swap-als-Datei - licence for the above content: http://creativecommons.org/licenses/by-nc-sa/2.0/de/deed.en (Attribution-NonCommercial-ShareAlike 2.0 Germany (CC BY-NC-SA 2.0 DE))
Related Topics
How to Sort a String's Characters Alphabetically
Uninitialized Constant Rake::Dsl in Ruby Gem
Rails Migration Changing Column to Use Postgres Arrays
Sprockets::Circulardependencyerror in Store#Index
How to Use Xmlns Declarations with Xpath in Nokogiri
How to Add MAC-Specific Gems to Bundle on MAC But Not on Linux
Migrating from Rails 2 to Rails 3
Has_Many While Respecting Build Strategy in Factory_Girl
How to Use Dot Syntax for Ruby Hash
Given the Session Key and Secret, How to Decrypt Rails Cookies
How to Share Variables Across My .Rb Files
Multiple Sinatra Apps Using Rack-Mount
Attr_Accessor Strongly Typed Ruby on Rails
Differences Between Proc and Lambda