S
YMBOLS
only one symbol object can exist for any given unit of text
:a:venue“a”.to_sym“a”.intern
U
NIQUENESS
OF
SYMBOLS
:a.equal?(:a) #output: true
R
AILS
STYLE
METHOD
ARGUMENTS
<%= link_to "Click here",:controller => "book",:action => "show",:id => book.id %>
Numerical Objects
S
ENDING
M
ESSAGES
TO
N
UMBERS
x=12x.zero?n = 98.6m = n.roundascii_value = 97.chrstr = 2.ro_s
C
OMMON
ARITHMETIC
EXPRESSIONS
ExpressionResultDescription
1 + 12Addition10/33Integer Division10.0/3.03.333333Floating-point Division-12 - - 7-5Subtraction negativenumber
N
ON
-
DECIMAL
NUMBERS
Hexadecimal integers
0x12 #equals 18
Octal integers (begin with 0)
012 #equals 10
to_i conversion from any base to decimal. Supply the baseto convert
from
as argument to to_i
“10”.to_i(17) #result: 17“12345”.to_i(13) #result: 33519
Times and Dates
Manipulated through three classes:
DateTimeDateTime
'require' the classes into your program to use them
M
ETHODS
d = Date.today #returns today's dateputs d << 2 #rewind date by 2 monthsputs d >> 5 #advance date by 5 monthst = Time.newt.yeart.montht.dayt.hourt.mint.sect.usect.strftime(“%m-%d-%Y”)
SpecifierDescription%YYear (4 digits)%yYear (las 2 digits)%b, %BShort month, full month%mMonth (number)%dDay of month (left padded with zeros)%eDay of months(left padded with blanks)%a, %AShort day name, full day name%H, %IHour (24h), hour (12h am/pm)%MMinute%SSecond%cEquals %a %b %d %H:%M:%S %Y
“ ”
%x Equals %m/%d/%y
“ ”
Arrays and Hashes
C
REATING
ARRAYS
a = Array.newa = []a = [1,2, “three”, 4]
You can initialize Array size and contents using Array.new
Array.new(3) #output: [nil,nil,nil]Array.new(3, “abc”)#output: [“abc”, “abc”, “abc”]
Array.new can also take code blocks
n = 0
Add a Comment