Browse Source

Start working on the real content of the presentation

master
Peter J. Jones 5 years ago
parent
commit
dd662d0ad7
9 changed files with 495 additions and 3 deletions
  1. 2
    0
      .gitignore
  2. 15
    0
      GNUmakefile
  3. 153
    0
      README.md
  4. 88
    0
      doc/plan.org
  5. 127
    2
      slides.md
  6. 41
    0
      src/intro.rb
  7. 36
    0
      src/syntax.rb
  8. 32
    0
      src/what.rb
  9. 1
    1
      vendor/devalot-slides

+ 2
- 0
.gitignore View File

@@ -1,2 +1,4 @@
/README.html
/slides.html
/slides.pdf
/src/tested.date

+ 15
- 0
GNUmakefile View File

@@ -1,2 +1,17 @@
################################################################################
TEST_HACK = src/tested.date
SRC_FILES = $(wildcard src/*.rb)

################################################################################
include vendor/devalot-slides/slides.mk
GEN_FILES += $(TEST_HACK)

################################################################################
all: $(TEST_HACK)
$(SOURCE:.md=.pdf): $(TEST_HACK)

################################################################################
$(TEST_HACK): $(SRC_FILES)
@ $(call MESSAGE,test src files)
@ for f in src/*.rb; do ruby $$f || exit 1; done
@ date > $@

+ 153
- 0
README.md View File

@@ -0,0 +1,153 @@
# Introduction

~~~~ {.ruby include="src/intro.rb" token="intro"}
class You
def ask_questions
end
end

class Me
def keep_on_track
end
end
~~~~



- Please ask questions at any time.
- Your job is to understand the material.
- My job is to keep us on track and on time.



# 30-second History of Ruby

~~~~ {.ruby include="src/intro.rb" token="in-30"}
Time.now + 30 * 60
~~~~

- When and where?
- Influences.
- “Modern” Ruby.



- First released in 1995 by Japanese Programmer “Matz”.
- Syntax influenced by Perl (C-style).
- Features influenced by Smalltalk and Lisp.
- Modern Ruby began with v1.9 (2007)
- Several Implementations, main is [MRI](http://www.ruby-lang.org).



# What is Ruby?

~~~~ {.ruby include="src/what.rb" token="is_a"}
ruby.is_a?(Language) &&
ruby.typing?(:dynamic) &&
ruby.memory?(:gc) # => true
~~~~



- Purely object-oriented.
- General purpose (not just web apps!)
- Dynamically typed.
- Garbage collected.



# Ruby Syntax

~~~~ {.ruby include="src/syntax.rb" token="person"}
class Person
def initialize (first, last)
@first_name = first
@last_name = last
end

def name
@first_name + ' ' + @last_name
end
end
~~~~

~~~~ {.ruby include="src/syntax.rb" token="new"}
Person.new("", "")
~~~~



- Perl-flavored, C-like syntax
- Semicolons are optional (line-based)
- Whitespace insignificant.
- Constants use CamelCase
- Variables and methods use snake\_case.
- Blocks of code are delimited by `begin...end` or `do...end`.
- All methods return a value (no `void` functions).
- Implicit return of final value.
- The scope of a variable is determined by its name.



# Everything is an Object



- Numeric literals are objects.
- String literals are objects.



# Everything is an Expression



- An `if` statement is really an expression.
- Using `if` in string interpolation.
- Class definition is an expression.
- Method definition is an expression.



# Object-oriented Programming



- Ruby only allows single inheritance.
- Multiple inheritance is emulated with modules.
- Modules *are not* interfaces.



# Everything is an Object (Part 2)



- Even classes are objects!



# Blocks



- Blocks are borrowed from Smalltalk.
- Blocks can be used as iterators (`Array#each`).
- And also for resource management (`File::open`).
- Long form: `do |x| ... end`.
- Short form: `{|x| ... }`.
- You can write methods which accept blocks.
- Blocks can be passed around from method to method.



# Closing



- Open IRB and ask questions.



+ 88
- 0
doc/plan.org View File

@@ -0,0 +1,88 @@
#+title: Presentation Planning
#+author: Peter Jones <pjones@devalot.com>
#+startup: overview

* Goals
** 1-hour Presentation
** 50% Lecture, 50% Action
* Outline
:PROPERTIES:
:COLUMNS: %50ITEM(Task) %5Effort(Estimate){:}
:VISIBILITY: children
:END:
** Introduction
:PROPERTIES:
:Effort: 02:00
:END:
- Ask questions at any time
- Your job is to understand
- My job is to keep us on time
** 30-second History of Ruby
:PROPERTIES:
:Effort: 02:00
:END:
- First release: 1995
- Syntax influenced by Perl
- Features influenced by Smalltalk and Lisp
- Modern Ruby starts at 1.9 (2007)
- Several implementations, main is MRI
** What is Ruby?
:PROPERTIES:
:Effort: 05:00
:END:
- Perl-flavored, C-like syntax (semicolons optional)
- Purely object-oriented
- Dynamically typed
- Garbage collected
** Ruby Syntax
:PROPERTIES:
:Effort: 08:00
:END:
- Example Ruby code
- Naming scheme
- `begin` ... `end` vs. curly braces
- Implicit return value
** Everything is an Object
:PROPERTIES:
:Effort: 05:00
:END:
- Open IRB:
- Play with numeric literals
- String literals: double quotes
** Everything is an Expression
:PROPERTIES:
:Effort: 10:00
:END:
- Open IRB:
- Play with `if`
- String interpolation
** Object-Oriented Programming
:PROPERTIES:
:Effort: 05:00
:END:
- Example code
- Single inheritance
- Emulated multiple inheritance through modules
- Modules *are not* interfaces.
- Variable names indicate their scope.
** Everything is an Object (Part 2)
:PROPERTIES:
:Effort: 05:00
:END:
- `Array.class`
** Blocks
:PROPERTIES:
:Effort: 15:00
:END:
- Example code (`Array#each`)
- Example code (`File::open`)
- Borrowed from Smalltalk
- Long form: `do |x|` ... `end`
- Short form `{|x| ...}`
- Alternative to deterministic destruction
- You can write methods which accept blocks
** Closing
:PROPERTIES:
:Effort: 03:00
:END:
- Open Q&A in IRB

+ 127
- 2
slides.md View File

@@ -2,6 +2,131 @@
% Peter Jones <pjones@devalot.com>
%

# Syntax Basics
# Introduction

Foo Bar.
~~~ {.ruby include="src/intro.rb" token="intro"}
~~~

<div class="notes">

* Please ask questions at any time.
* Your job is to understand the material.
* My job is to keep us on track and on time.

</div>

# 30-second History of Ruby

~~~ {.ruby include="src/intro.rb" token="in-30"}
~~~

* When and where?
* Influences.
* "Modern" Ruby.

<div class="notes">

* First released in 1995 by Japanese Programmer "Matz".
* Syntax influenced by Perl (C-style).
* Features influenced by Smalltalk and Lisp.
* Modern Ruby began with v1.9 (2007)
* Several Implementations, main is [MRI] [].

</div>

# What is Ruby?

~~~ {.ruby include="src/what.rb" token="is_a"}
~~~

<div class="notes">

* Purely object-oriented.
* General purpose (not just web apps!)
* Dynamically typed.
* Garbage collected.

</div>

# Ruby Syntax

~~~ {.ruby include="src/syntax.rb" token="person"}
~~~
~~~ {.ruby include="src/syntax.rb" token="new"}
~~~

<div class="notes">

* Perl-flavored, C-like syntax
* Semicolons are optional (line-based)
* Whitespace insignificant.
* Constants use CamelCase
* Variables and methods use snake_case.
* Blocks of code are delimited by `begin...end` or `do...end`.
* All methods return a value (no `void` functions).
* Implicit return of final value.
* The scope of a variable is determined by its name.

</div>

# Everything is an Object

<div class="notes">

* Numeric literals are objects.
* String literals are objects.

</div>

# Everything is an Expression

<div class="notes">

* An `if` statement is really an expression.
* Using `if` in string interpolation.
* Class definition is an expression.
* Method definition is an expression.

</div>

# Object-oriented Programming

<div class="notes">

* Ruby only allows single inheritance.
* Multiple inheritance is emulated with modules.
* Modules *are not* interfaces.

</div>

# Everything is an Object (Part 2)

<div class="notes">

* Even classes are objects!

</div>

# Blocks

<div class="notes">

* Blocks are borrowed from Smalltalk.
* Blocks can be used as iterators (`Array#each`).
* And also for resource management (`File::open`).
* Long form: `do |x| ... end`.
* Short form: `{|x| ... }`.
* You can write methods which accept blocks.
* Blocks can be passed around from method to method.

</div>

# Closing

<div class="notes">

* Open IRB and ask questions.

</div>

[mri]: http://www.ruby-lang.org

+ 41
- 0
src/intro.rb View File

@@ -0,0 +1,41 @@
#!ruby -w

################################################################################
require('minitest/autorun')

################################################################################
class IntroTest < MiniTest::Unit::TestCase

##############################################################################
# <<: intro
class You
def ask_questions
# ...
end
end

class Me
def keep_on_track
# ...
end
end
# :>>

##############################################################################
def test_intro
assert(You.new.respond_to?(:ask_questions))
assert(Me.new.respond_to?(:keep_on_track))
end

##############################################################################
def time_in_30
# <<: in-30
Time.now + 30 * 60
# :>>
end

##############################################################################
def test_time
assert(time_in_30 > Time.now)
end
end

+ 36
- 0
src/syntax.rb View File

@@ -0,0 +1,36 @@
#!ruby -w

################################################################################
require('minitest/autorun')

################################################################################
class SyntaxTest < MiniTest::Unit::TestCase

##############################################################################
# <<: person
class Person
def initialize (first, last)
@first_name = first
@last_name = last
end

def name
@first_name + ' ' + @last_name
end
end
# :>>

##############################################################################
def new_person
# <<: new
character = Person.new("Sheldon", "Cooper")
character.name
# :>>
character
end

##############################################################################
def test_new_person
assert_equal("Sheldon Cooper", new_person.name)
end
end

+ 32
- 0
src/what.rb View File

@@ -0,0 +1,32 @@
#!ruby -w

################################################################################
require('minitest/autorun')

################################################################################
class WhatTest < MiniTest::Unit::TestCase

##############################################################################
class Language; end

##############################################################################
class Ruby < Language
def typing? (*) true; end
def memory? (*) true; end
end

##############################################################################
def what
ruby = Ruby.new
# <<: is_a
ruby.is_a?(Language) &&
ruby.typing?(:dynamic) &&
ruby.memory?(:gc) # => true
# :>>
end

##############################################################################
def test_what
assert(what)
end
end

+ 1
- 1
vendor/devalot-slides

@@ -1 +1 @@
Subproject commit e5227d567b38709d25c2012e276db04ebc2f112e
Subproject commit a76b0b707a1e2147476c480e23aef897dbcffd41

Loading…
Cancel
Save