Errors / Debugging / Despair
Read Docs / Stack Overflow
Presenting Data
Getting Data
Your Idea
You
Slide 5
Slide 5 text
Errors / Debugging / Despair
Read Docs / Stack Overflow
Presenting Data
Getting Data
Your Idea
You
Slide 6
Slide 6 text
Errors / Debugging / Despair
Read Docs / Stack Overflow
Presenting Data
Getting Data
Your Idea
You
Slide 7
Slide 7 text
Errors / Debugging / Despair
Read Docs / Stack Overflow
Presenting Data
Getting Data
Your Idea
You
Slide 8
Slide 8 text
Errors / Debugging / Despair
Read Docs / Stack Overflow
Presenting Data
Getting Data
Your Idea
You
Slide 9
Slide 9 text
Writing code is
*
*Ruby makes it nicer
Slide 10
Slide 10 text
Ruby is expressive
What you expect to happen is usually what
happens
Slide 11
Slide 11 text
Ruby is readable
Reading code like a machine isn’t so nice
Slide 12
Slide 12 text
Ruby is for people
There’s plenty of other languages optimised for
machines
Slide 13
Slide 13 text
Brewbot.brew! do
recipe "Ruby on Ales" do
ingredient :water
ingredient malts: [
"British Pale Ale Malt",
"Crystal Malt",
"Munich Malt"
]
!
ingredient hops: ["Colombus", "Cascade"]
end
end
!
Slide 14
Slide 14 text
–Someone
“But I can already do these things in [x]
language, see!”
Slide 15
Slide 15 text
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/100/30/10
> +++++ ++ add 7 to cell #1
> +++++ +++++ add 10 to cell #2
> +++ add 3 to cell #3
> + add 1 to cell #4
<<<< - decrement counter (cell #0)
]
> ++ . print 'H'
> + . print 'e'
+++++ ++ . print 'l'
. print 'l'
+++ . print 'o'
> ++ . print ' '
<< +++++ +++++ +++++ . print 'W'
> . print 'o'
+++ . print 'r'
----- - . print 'l'
----- --- . print 'd'
> + . print '!'
> .
Hello World!
Slide 16
Slide 16 text
[“Pun
Slide 17
Slide 17 text
Comparing to Objective-C*
*This is a totally ridiculous comparison I know
Slide 18
Slide 18 text
beers = ["Rochefort 8", "Carlsberg"] + ["Pliny the Elder", "Harp"]
=> ["Rochefort", "Carlsberg", "Pliny the Elder", "Harp"]
!
nice_beers = beers - ["Carlsberg", "Harp"]
=> ["Rochefort", "Pliny the Elder”]
!
nice_beers = nice_beers + ["The Kernel Pale Ale"]
=> ["Rochefort", "Pliny the Elder", "The Kernel Pale Ale"]
Arrays in Ruby
Slide 19
Slide 19 text
NSMutableArray *beers = [@[@"Rochefort 8", @"Carlsberg", @"Pliny
the Elder", @"Harp"] mutableCopy];
=> ["Rochefort", "Carlsberg", "Pliny the Elder", “Harp"]
!
NSMutableArray *nice_beers = [beers mutableCopy];
[nice_beers removeObjectsInArray:@[@"Carlsberg", @"Harp"]];
=> ["Rochefort", "Pliny the Elder"]
!
[nice_beers addObject:@"The Kernel Pale Ale"];
=> ["Rochefort", "Pliny the Elder", "The Kernel Pale Ale"]
Arrays* in Objective-C
Slide 20
Slide 20 text
nice_beers.each do |beer|
puts "I like " + beer
end
!
=> I like Rochefort 8
=> I like Pliny the Elder
=> I like The Kernel Pale Ale
=> ["Rochefort 8", "Pliny the Elder", "The Kernel Pale Ale"]
Arrays and Blocks in
Ruby
Slide 21
Slide 21 text
[nice_beers enumerateObjectsUsingBlock:
^(NSString *beer, NSUInteger idx, BOOL *stop) {
NSLog(@"I like %@", beer);
}];
!
=> I like Rochefort 8
=> I like Pliny the Elder
=> I like The Kernel Pale Ale
Arrays and Blocks in
Objective-C
Slide 22
Slide 22 text
Beer.create name: "Ruby on Ales"
Saving models using
Ruby on Rails
Slide 23
Slide 23 text
NSManagedObjectContext *managedContext = [NSManagedObjectContext new];
Beer *beer = [Beer createInContext:managedContext];
beer.name = @"Ruby on Ales";
NSError *error = nil;
[managedContext save:&error];
Saving models in
Objective-C using Core Data
Slide 24
Slide 24 text
Quick and Simple
Tasks with Ruby
Write a script or use irb