Ruby: An Introduction: Jorge Chao University of New Orleans Slides Available As PDF at WWW - Cs.Uno - Edu/ Jchao/Rubyintro PDF
Ruby: An Introduction: Jorge Chao University of New Orleans Slides Available As PDF at WWW - Cs.Uno - Edu/ Jchao/Rubyintro PDF
Jorge Chao
University of New Orleans
•
Thursday, April 28, 2011
Dynamic Typing
•
Thursday, April 28, 2011
Built-in Types
• Numbers are represented by either the
Fixnum, Bignum or Float types (all children of
Numeric).
• Fixnum holds 32-bit Integer values
• Fixnum overflows upconvert to Bignum,
which is considered an infinite-length
bitstring with 2’s compliment notation.
• Float is used for representing real numbers.
Thursday, April 28, 2011
Numbers
• Basic Numeric Operations
•
Thursday, April 28, 2011
Numbers
• Ruby makes an object of type Float any
time a decimal point is used.
• The number must have a digit following the
decimal, as Ruby can perform class
operations on numbers.
• Ruby implicitly casts the result of an
arithmetic operation between a Float and a
Fixnum to a Float.
•
Thursday, April 28, 2011
Strings
• Incomplete list of built in String functions
• % * + << <=> == =~ capitalize
center chomp chop concat count crypt
delete downcase dump each empty?
end_regexp eql? gsub hash include?
index insert intern is_complex_yaml?
length match oct quote replace reverse
scan scanf size slice split squeeze strip
sub swapcase to_f to_i to_s to_str
to_sym to_yaml tr tr_s upcase upto
Thursday, April 28, 2011
Data Structures
•
Thursday, April 28, 2011
Hashes
• Some basic hash manipulation, notice the use
of :symbols, I’ll cover them in a minute.
•
Thursday, April 28, 2011
Iterators
• What would collections of things be if we
couldn’t iterate over them?
• Most iteration in Ruby is done using a do
block.
• All iterations in Ruby are accomplished by
passing callback closures to container
methods.
•
Thursday, April 28, 2011
Classes
• Classes start with the class keyword, end
them with...end.
•
Thursday, April 28, 2011
Essence Vs. Ceremony
• An idea from Stu Halloway at Relevance Inc.
• “Good Code is the opposite of legacy
code: it captures and communicates essence
while omitting ceremony (irrelevant detail).”
• The design philosophy of the language
determines what kind of code you write
with it.
•
Thursday, April 28, 2011
More on Symbols
• Kevin Clark, Ruby Developer says:
• “The intention of symbols are for
identification of (user-level, primarily)
constructs: a slot in a hash, a method, an
option, etc.”
• That’s the great thing about symbols, they
can refer to variables or methods.
•
Thursday, April 28, 2011
Using Object.send
• Object.send takes a symbol or string as
parameter.
•
Thursday, April 28, 2011
More on Reflection