Wednesday, February 8, 2017

Try Ruby Tutorial

A really cool thing about Ruby is that you can always convert between different types using Ruby's "to" methods.
  • to_s converts values to strings.
  • to_i converts values to integers (numbers.)
  • to_a converts values to arrays.
Strings have .reverse property eg "Chee".reverse => "eejC"

ARRAYS

Arrays are basically list of stored information.

Create empty array
[]

[517, 66, 07].max => 517

Assign array to a variable

nric=>[517, 66, 07]

Sort an Array

nric.sort =>[07,66,517]
nric=>[517, 66, 07]

// ! permanently sort 
nric.sort! =>[07,66,517]
nric =>[07,66,517]

Query Array

nric.include? 67 =>false
nric.include? 07 =>true

Comple list of string methods

Hash
Hashes store related information by giving reusable labels to pieces of data.

Create Hash aka Dictionary.
books={}

or

ratings=Hash.new(0)

Stuffing an Array

books["Inferno"] = :splendid
books["Kublai Khan"] = :historical
books["Davinci Code"]=:exciting

books => {"Inferno"=>:splendid, "Kublai Khan=>:historical, "Davinci Code"=>:exciting}


Block


Basically, a block is a chuck of ruby code


No comments:

Welcome to Rails.. Rails... Rails !

In 1995, I started the popular Clipper...Clipper... Clipper website (no blogs then) which was very popular and linked by virtually every Clipper-related site. When I switched to Windows via Delphi in 1997, I started the Delphi... Delphi... Delphi site. In June 2007, I discovered Ruby on Rails and no prize for guessing what I am gonna name this blog. which I started on 2nd October 2007.

As at 10th June 2010, we have 13,364 unique visitors from more than 84 countries such as Angola, Andorra, Argentina, Australia, Austria, Algeria,Barbados, Bosnia and Herzogovina, Belgium, Brazil, Bulgaria, Bangladesh, Belarus, Bolivia, Chile, Cambodia, Cape Vede, Canada, China, Colombia, Costa Rica, Croatia, Cyprus, Czech Republic, Denmark, Egypt, Estonia, Finland, France, Guadeloupe, Guatemala, Germany, Greece, Hong Kong, Hungary, India, Indonesia, Ireland, Israel, Italy, Japan, Kenya, Korea, Lithuania, Latvia, Malaysia, Mexico, Macao, Netherlands, Nepal, Norway, New Zealand, Oman, Panama, Peru, Poland, Portugal,Paraguay , Philippines, Romania, Russian Federation, Saudi Arabia, Singapore, Spain, Slovakia, Slovenia, Serbia, South Korea, Slovenia, South Africa, Spain, Switzerland, Sri Lanka, Sweden, Taiwan, Thailand, Turkey, United Arab Emirates, Ukraine, USA, UK, Venezuela, Vietnam

CCH
10th June 2010, 19:42