#+TITLE: Seven Languages in Seven Weeks
#+BEAMER_HEADER: \subtitle{Ruby}
#+BEAMER_HEADER: \institute[INST]{Extreme Tech Seminar}
#+AUTHOR: Correl Roush
#+EMAIL: correl@gmail.com
#+DATE: May 27, 2015
#+OPTIONS: H:2 toc:nil ^:nil
#+STARTUP: beamer indent
#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_act(Act) %4BEAMER_col(Col) %8BEAMER_opt(Opt)
#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC
#+LaTeX_CLASS: beamer
#+LaTeX_CLASS_OPTIONS: [presentation,aspectratio=169]

* Introduction
** Introduction
*** Ruby                                                            :BMCOL:
:PROPERTIES:
:BEAMER_col: 0.5
:END:
- Created :: ~1993
- Author :: Yukihiro Matsumoto

Interpreted, object-oriented, and dynamically typed.
*** Mary Poppins                                                    :BMCOL:
:PROPERTIES:
:BEAMER_col: 0.5
:END:
#+ATTR_LATEX: width=\textwidth
[[file:mary_poppins_remake_by_gali_miau-d4nyzkc.jpg]]
** Getting Ruby
http://www.ruby-lang.org/en/downloads/
** Example
*** Source
#+name: ruby-intro
#+BEGIN_SRC ruby :results output :exports both
  properties = ['object oriented', 'duck typed',
                'productive', 'fun']
  properties.each {|property| puts "Ruby is #{property}."}
#+END_SRC

*** Output
#+RESULTS: ruby-intro
: Ruby is object oriented.
: Ruby is duck typed.
: Ruby is productive.
: Ruby is fun.

* Day 1
** Day 1: Finding a Nanny                                           :B_frame:
:PROPERTIES:
:BEAMER_env: frame
:END:
- Object-Oriented
- Simple Conditionals
- Strong / Dynamic Typing
- Duck Typing
** Duck Typing
*** Source
#+name: ruby-duck-typing
#+BEGIN_SRC ruby :results output :exports both
  i = 0
  a = ['100', 100.0]
  while i < 2
    puts a[i].to_i
    i = i + 1
  end
#+END_SRC

*** Output
#+RESULTS: ruby-duck-typing
: 100
: 100

** Exercises
#+BEGIN_CENTER
EXERCISES
#+END_CENTER
* Day 2
** Day 2: Floating Down from the Sky
- Defining Functions
- Arrays
- Hashes
- Code Blocks and Yield
- Running Ruby from a File
- Defining Classes
- Writing a Mixin
- Modules, Enumerable, and Sets
** Defining Functions
#+BEGIN_SRC ruby
  def tell_the_truth
    true
  end
#+END_SRC
** Code Blocks
*** Source
#+name: ruby-blocks
#+BEGIN_SRC ruby :results output :exports both
  class Fixnum
    def my_times
      i = self
      while i > 0
        i = i - 1
        yield
      end
    end
  end

  3.my_times {puts 'mangy moose'}
#+END_SRC

*** Results
#+RESULTS: ruby-blocks
: mangy moose
: mangy moose
: mangy moose

** Classes
[[file:ruby-metamodel.png]]

** Exercises
#+BEGIN_CENTER
EXERCISES
#+END_CENTER
* Day 3
** Day 3: Serious Change
- Open Classes
- =method_missing=
- Modules
** method_missing
*** Source                                                          :BMCOL:
:PROPERTIES:
:BEAMER_col: 0.7
:END:
#+name: ruby-method-missing
#+BEGIN_SRC ruby :results output :exports both
  class Roman
    def self.method_missing name, *args
      roman = name.to_s
      roman.gsub!("IV", "IIII")
      roman.gsub!("IX", "VIIII")
      roman.gsub!("XL", "XXXX")
      roman.gsub!("XC", "LXXXX")

      (roman.count("I") +  
       roman.count("V") * 5 +
       roman.count("X") * 10 + 
       roman.count("L") * 50 +
       roman.count("C") * 100)
    end
  end

  puts Roman.X
  puts Roman.XC
  puts Roman.XII
  puts Roman.X
#+END_SRC
*** Results                                                         :BMCOL:
:PROPERTIES:
:BEAMER_col: 0.3
:END:
#+RESULTS: ruby-method-missing
: 10
: 90
: 12
: 10

** Exercises
#+BEGIN_CENTER
EXERCISES
#+END_CENTER
* Wrapping Up
** Wrapping Up: Core Strengths
- Scripting
- Web Development
- Time to Market
** Wrapping Up: Weaknesses
- Performance
- Concurrency and OOP
- Type Safety
** Final Thoughts
Syntax and flexibility vs. performance.