In our third session we covered the second half of our language crash course. This session addresses Arrays, Hashes, Symbols, Control Structures, Regular Expressions, Blocks and Iterators.
7. Hashes
⢠Hashes are unordered lists of values
⢠Hashes are indexed using âkeysâ which can
being either strings or symbols
8. Hashes
hash = {âoneâ => âOneâ, :two => âTwoâ}
puts hash[âoneâ]
One
puts hash[:two]
Three
9. Symbols
⢠Symbols are essentially constants that donât
need to be declared ahead of time
⢠A Symbol has a simple string-like
representation and is guaranteed to have a
unique value
11. Symbols
⢠Symbols are most commonly found as the
keys for hashes
⢠They are slightly more memory efďŹcient than
using strings for the same purposes
12. Control Structures
⢠Control structures allow you to handle
conditional behaviors
⢠Control structures allow you to handle
iterations/loops
13. Control Structures
⢠if ... else ... elsif
⢠while
⢠case ... when
⢠for ... in
⢠until
⢠unless
20. Regular Expressions
⢠Regular Expressions are used for text parsing
and manipulation
⢠They can represent a sort of programming
language unto themselves
21. Blocks
⢠Sections of code that can be passed to
methods like parameters
⢠Represented as code within curly braces or
between do and end
22. Blocks
def call_block
puts "Start of method"
yield
puts "End of method"
end
call_block { puts "In the block" }
Start of method
In the block
End of method
23. Iterators
⢠A type of code block that works with
successive values of some collection
⢠Used extensively for arrays and hashes
26. For Next Week
For the New to Programming
⢠Read Chapters 5, 6, 7 & 8 in LtP
⢠Complete exercises for each chapter
For Everyone
⢠Read Chapter 2, 7 & 9 in PR1.9
⢠Work on the Ruby Koans at a leisurely
pace