Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby on Ales

Ruby on Ales

A brief introduction on to Ruby, highlighting its expressiveness and readability with some comparisons to Objective C.

Companion notes - http://git.io/P1lA5w

Kieran Graham

February 04, 2014
Tweet

More Decks by Kieran Graham

Other Decks in Programming

Transcript

  1. Errors / Debugging / Despair Read Docs / Stack Overflow

    Presenting Data Getting Data Your Idea You
  2. Errors / Debugging / Despair Read Docs / Stack Overflow

    Presenting Data Getting Data Your Idea You
  3. Errors / Debugging / Despair Read Docs / Stack Overflow

    Presenting Data Getting Data Your Idea You
  4. Errors / Debugging / Despair Read Docs / Stack Overflow

    Presenting Data Getting Data Your Idea You
  5. Errors / Debugging / Despair Read Docs / Stack Overflow

    Presenting Data Getting Data Your Idea You
  6. 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 !
  7. +++++ +++++ 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!
  8. 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
  9. 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
  10. 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
  11. [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
  12. 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
  13. 2.0.0-p353 :002 > 2 + 2 => 4 2.0.0-p353 :003

    > [1,2,3,4] + [5,6,7,8] => [1, 2, 3, 4, 5, 6, 7, 8] 2.0.0-p353 :004 > irb - Interactive Ruby Shell
  14. RVM can help Ruby Version Manager lets you have multiple

    Rubies installed beside but isolated from each other
  15. Thanks Enjoy some of the Ruby on Ales beer specially

    brewed for Belfast Ruby by Brewbot ! @kierangraham @brewbot