Week 1 - Overview
Students should be comfortable with the following at the end of this week:
- Ruby Basics
- Control Flow
- Variables
- Methods
- Arrays and Hashes
- Objects and Classes
Important Links
Monday - Control Flow and Variables
- Class Logistics
- Daily schedule
- Exercises, Assignments, and Projects
- Readings
- Pair-question-asking
- Human Learning
- Definition: Acquiring knowledge and skills and having them readily available from memory so you can make sense of future problems and opportunities.
- ON BOARD: To learn, you should… Get related knowledge in advance
- Comfort, Learning, and Panic Zones
- DIAGRAM: Three Concentric Zones
- On BOARD: Expect to exert effort
- Programming Languages
- What are they?
- How many are there?
- What makes Ruby special?
- MINASWAN
- Why Ruby is not the same thing as Ruby on Rails
- Terminal
- Mac file system
pwd
ls
cd
/
and ~
- Instructions - PB & J
- Control Flow
- PB & J for the entire class. Use a
while
, maybe an if
.
if
, else
, elsif
, end
while
loop
- Indentation
- Variables
- PB & J for the entire class, everyone wants a different jelly.
- EXAMPLE: Write and execute Ruby code which asks the user for a word and tells the user whether the word is a palindrome. Let it ask for a total of five words.
- Logical Statements
- Concepts of
and
and or
- While someone still wants a sandwich
- While someone still wants a sandwich AND I still have bread
- If
selection == "Strawberry"
OR selection == "Raspberry"
- EXAMPLE: I want to edit a comment on a forum. I can do that if I’m logged in and it’s my comment or if I’m an admin.
==
vs =
!
- Data Types
- Strings
- Integers
- Floats
1/3
, 2/3
- Dates
- DateTimes
- Print/Get
- Running Ruby
- From the command line
- From irb
Lecture Notes/Links
Evening Reading
Assignment
User Input Statistics
Tuesday - Methods and Arrays
Problem of the Day: The 12 Days of Christmas
- Data Structures
- Ranges
- Arrays
+
vs <<
.each
- More on Variables
- Proper Ruby variable naming
- Two names for the same variable
- How variables are stored in memory
- How memory is different from hard disk
- Binary
- How to store integers
- How to store strings
- Type conversions (
to_i
, to_f
, etc)
2.3+3.4
- Floating Point Errors
- Decimal (later)
- Methods
- Return values vs side effects (including
puts
)
- Scope
- Parameters
- Default parameters
- Defining the same method twice
- Common Error Messages
- NameError (
undefined local variable
)
- NoMethodError (
nil.reverse
)
- ArgumentError
- TypeError (
2+"1"
)
- Git
- Reason: keep different versions over time
- Reason: backups
git init
git add
git commit
- New repository on GitHub
git push
- XKCD on Git
- Editors (and pros and cons of the default vim)
rand
Lecture Notes/Links
Evening Reading
Assignment
Number Guessing Game
Wednesday - Hashes and Nested Data Structures
Problem of the Day: Phone Numbers
- Random Topics
- Methods which return versus methods which have side effects. We only did side effects yesterday!
- predicate methods
if
commands on one line
return
- Parentheses when calling or defining methods
- Customizing your
PS1
- Flycut for copy history
- Vertical select via Atom’s Sublime-Style-Column-Selection package
- Control Flow (in light of Number Guessing Game)
- next (not lose a turn if you guess the same thing twice)
- break (stop asking when the correct number is guessed)
- return
- exit
- POD Attempt 1: Array
- Just names first. Ask for everyone’s name and display them all at the end.
- How do I prevent duplicates when I enter a name more than once?
- Attempt 2: Set
- Basic
require
from standard library
- Core library vs. Standard library
- Attempt 3: Hash
- Keep track of a phone number for each person
- Interlude: How do we show something other than a blank when a person hasn’t had a phone number entered?
- Use a ternary to output a nice “(Not Found)” string
- What is “truthy” and what is “falsey” in Ruby?
- What does
if
or while
actually expect?
- What does an
||
call return? (true || false
, "Mason" || false
, etc)
- Attempt 4: Hashes inside a Hash
- Keep track of a phone number and an email address and a birthdate for each person
- Attempt 5: Arrays inside Hashes
- Keep track of multiple email addresses for each person.
- Git/GitHub Conventions
Lecture Notes/Links
Evening Reading
Assignment
Blackjack Advisor
Thursday - Classes
Problem of the Day: Albums and Artists
- Check-in on Readings
- Object Oriented Programming
- In-Class Example: Cell Phone Assignments
- What are objects?
- State and behavior
- State = instance variables
- Behavior = methods
- Everything in Ruby is messages being passed to objects!!!
- Example of how we’ve been using strings.
- What are classes?
- Encapsulation
- Math is messages being passed to objects as well!!!
2 + 2.3
2.+(2.3)
- Overriding arithmetic operations (e.g.
def +(other) ... end
)
- Ruby code in multiple files
- Symbols
Lecture Notes/Links
Evening Reading
Weekend Assignment
Currency Converter