[Solid Ruby Basics] Ruby Quick Start, solid ruby Quick Start
Address: http://www.cnblogs.com/aiweixiao/p/6664301.html
Document outline
Scan the public account
1. Ruby Installation
1.1) [install Ruby]
Ruby installation on Linux/Unix
Ruby installation on Windows
$ Sudo yum install ruby # CentOS, Fedora, or RHEL system or sudo apt-get install ruby-full # Debian or Ubuntu System
$ Brew install ruby # Apple System
1.2) [interactive Ruby (IRb )]
TypeIrb, An interactive Ruby Session will start
2. Ruby syntax
2.1) [String]
-- [Output]
1 puts "Hello, world!"
-- [Chinese encoding]
Garbled characters are displayed in Chinese. The solution is to add the content at the beginning of the file.#-*-Coding: UTF-8 -*-(EMAC) or# Coding = UTF-8That's all.
#! /Usr/bin/ruby-w #-*-coding: UTF-8-*-puts "Hello, world! ";
2.2) [Class]
class Customerend
-- A ruby class must be defined before it can be used.
-- Sample Code
#!/usr/bin/ruby class Customer @@no_of_customers=0 def initialize(id, name, addr) @cust_id=id @cust_name=name @cust_addr=addr end def display_details() puts "Customer id #@cust_id" puts "Customer name #@cust_name" puts "Customer address #@cust_addr" end def total_no_of_customers() @@no_of_customers += 1 puts "Total number of customers: #@@no_of_customers" endend