learn ruby at ASIT
-
Upload
asit-education -
Category
Documents
-
view
4 -
download
0
description
Transcript of learn ruby at ASIT
The Ruby Programming Language
The Ruby Programming Language
Object OrientationRuby is fully object oriented; everything is an object.Inheritance is shown by blue, :size => 6, :price => 24.95}To retrieve an element, use square brackets@size = order[:size]
Control Structures: Conditionalsif order[:color] == blueelsif order[:size] == 6elseend
Control Structures: Iterationfor, while and untilfor item in order doputs itemIterator eachsum = 0[1..10].each do |count| sum += countendputs sumcount is a parameter to the block and has no value outside of it.
Exceptionsbeginrescuerescueensureendrescue and ensure are the same as catch and finallyRuby also has throw and catch, similar to Java
ConventionsClass names begin with upper case letters.Method and variable names use lower case.For names with more than one word:Class names use camel (or bumpy) caseclass ActiveRecordMethod and variable names separate words with underscores.def show_person@little_girlIn Rails, table names are the plurals of the record namesSingle record is courseTable is called coursesBut the model class is called Course.