Ruby

From Things and Stuff Wiki
Revision as of 16:52, 4 December 2016 by Milk (talk | contribs) (→‎CMS/F)
Jump to navigation Jump to search


Basics

  • Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

Syntax

# The Greeter class
class Greeter
  def initialize(name)
    @name = name.capitalize
  end
 
  def salute
    puts "Hello #{@name}!"
  end
end
 
# Create a new object
g = Greeter.new("world")
 
# Output "Hello World!"
g.salute

Installing

rbenv

ruby-install

installing
wget -O ruby-install-0.3.0.tar.gz https://github.com/postmodern/ruby-install/archive/v0.3.0.tar.gz
tar -xzvf ruby-install-0.3.0.tar.gz
cd ruby-install-0.3.0/
sudo make install
usage

Install the current stable version of Ruby:

ruby-install ruby

Install a latest version of Ruby:

ruby-install ruby 1.9

Install a specific version of Ruby:

ruby-install ruby 1.9.3-p429

Install a Ruby into a specific directory:

ruby-install -i /usr/local/ ruby 1.9.3-p429

Install a Ruby from a mirror:

ruby-install -M http://www.mirrorservice.org/sites/ftp.ruby-lang.org/pub/ruby ruby 2.0.0-p247

Install a Ruby with a specific patch:

ruby-install -p https://raw.github.com/gist/4136373/falcon-gc.diff ruby 1.9.3-p429

Install a Ruby with specific configuration:

ruby-install ruby 2.0.0 -- --enable-shared --enable-dtrace CFLAGS="-O3"

Guides

RubyGems

Guides

  • isitruby1.9 Community-powered gem compatibility for ruby 1.9]

Installing

ruby setup.rb

Usage

gem update --system
gem install [rubygem]
  install a gem
gem upgrade
  upgrade installed gems
gem env

As user, goes into .gem. As root, goes into /usr/lib/ruby/gems/1.9.1/gems/compass-0.11.7/frameworks/compass/stylesheets/compass or suchlike.

ruby -r rubygems -e "p Gem.path"   
  display ruby gem path[s]

to sort

Tools

  • Pry is a powerful alternative to the standard IRB shell for Ruby. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing.
  • Sprockets is a Ruby library for compiling and serving web assets. It features declarative dependency management for JavaScript and CSS assets, as well as a powerful preprocessor pipeline that allows you to write assets in languages like CoffeeScript, Sass, SCSS and LESS.

Rails

Shoes

Development

  • jim - jim is your friendly javascript library manager. He downloads, stores, bundles, vendors and compresses.

Sinatra

require 'sinatra'

get '/hi' do
  "Hello World!"
end
gem install sinatra
ruby hi.rb

CMS/F



Mobile apps

Other

JavaScript

  • Opal is a ruby to javascript compiler. It is source-to-source, making it fast as a runtime. Opal includes a compiler (which can be run in any browser), a corelib and runtime implementation. The corelib/runtime is also very small (10.8kb gzipped).
  • RubyJS is a JavaScript implementation of all methods from Ruby classes like Array, String, Numbers, Time and more.