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 @@
1 1
 /README.html
2 2
 /slides.html
3
+/slides.pdf
4
+/src/tested.date

+ 15
- 0
GNUmakefile View File

@@ -1,2 +1,17 @@
1
+################################################################################
2
+TEST_HACK = src/tested.date
3
+SRC_FILES = $(wildcard src/*.rb)
4
+
1 5
 ################################################################################
2 6
 include vendor/devalot-slides/slides.mk
7
+GEN_FILES += $(TEST_HACK)
8
+
9
+################################################################################
10
+all: $(TEST_HACK)
11
+$(SOURCE:.md=.pdf): $(TEST_HACK)
12
+
13
+################################################################################
14
+$(TEST_HACK): $(SRC_FILES)
15
+	@ $(call MESSAGE,test src files)
16
+	@ for f in src/*.rb; do ruby $$f || exit 1; done
17
+	@ date > $@

+ 153
- 0
README.md View File

@@ -0,0 +1,153 @@
1
+# Introduction
2
+
3
+~~~~ {.ruby include="src/intro.rb" token="intro"}
4
+class You
5
+  def ask_questions
6
+    …
7
+  end
8
+end
9
+
10
+class Me
11
+  def keep_on_track
12
+    …
13
+  end
14
+end
15
+~~~~
16
+
17
+
18
+
19
+-   Please ask questions at any time.
20
+-   Your job is to understand the material.
21
+-   My job is to keep us on track and on time.
22
+
23
+
24
+
25
+# 30-second History of Ruby
26
+
27
+~~~~ {.ruby include="src/intro.rb" token="in-30"}
28
+Time.now + 30 * 60
29
+~~~~
30
+
31
+-   When and where?
32
+-   Influences.
33
+-   “Modern” Ruby.
34
+
35
+
36
+
37
+-   First released in 1995 by Japanese Programmer “Matz”.
38
+-   Syntax influenced by Perl (C-style).
39
+-   Features influenced by Smalltalk and Lisp.
40
+-   Modern Ruby began with v1.9 (2007)
41
+-   Several Implementations, main is [MRI](http://www.ruby-lang.org).
42
+
43
+
44
+
45
+# What is Ruby?
46
+
47
+~~~~ {.ruby include="src/what.rb" token="is_a"}
48
+ruby.is_a?(Language)     &&
49
+  ruby.typing?(:dynamic) &&
50
+  ruby.memory?(:gc)      # => true
51
+~~~~
52
+
53
+
54
+
55
+-   Purely object-oriented.
56
+-   General purpose (not just web apps!)
57
+-   Dynamically typed.
58
+-   Garbage collected.
59
+
60
+
61
+
62
+# Ruby Syntax
63
+
64
+~~~~ {.ruby include="src/syntax.rb" token="person"}
65
+class Person
66
+  def initialize (first, last)
67
+    @first_name = first
68
+    @last_name  = last
69
+  end
70
+
71
+  def name
72
+    @first_name + ' ' + @last_name
73
+  end
74
+end
75
+~~~~
76
+
77
+~~~~ {.ruby include="src/syntax.rb" token="new"}
78
+Person.new("", "")
79
+~~~~
80
+
81
+
82
+
83
+-   Perl-flavored, C-like syntax
84
+-   Semicolons are optional (line-based)
85
+-   Whitespace insignificant.
86
+-   Constants use CamelCase
87
+-   Variables and methods use snake\_case.
88
+-   Blocks of code are delimited by `begin...end` or `do...end`.
89
+-   All methods return a value (no `void` functions).
90
+-   Implicit return of final value.
91
+-   The scope of a variable is determined by its name.
92
+
93
+
94
+
95
+# Everything is an Object
96
+
97
+
98
+
99
+-   Numeric literals are objects.
100
+-   String literals are objects.
101
+
102
+
103
+
104
+# Everything is an Expression
105
+
106
+
107
+
108
+-   An `if` statement is really an expression.
109
+-   Using `if` in string interpolation.
110
+-   Class definition is an expression.
111
+-   Method definition is an expression.
112
+
113
+
114
+
115
+# Object-oriented Programming
116
+
117
+
118
+
119
+-   Ruby only allows single inheritance.
120
+-   Multiple inheritance is emulated with modules.
121
+-   Modules *are not* interfaces.
122
+
123
+
124
+
125
+# Everything is an Object (Part 2)
126
+
127
+
128
+
129
+-   Even classes are objects!
130
+
131
+
132
+
133
+# Blocks
134
+
135
+
136
+
137
+-   Blocks are borrowed from Smalltalk.
138
+-   Blocks can be used as iterators (`Array#each`).
139
+-   And also for resource management (`File::open`).
140
+-   Long form: `do |x| ... end`.
141
+-   Short form: `{|x| ... }`.
142
+-   You can write methods which accept blocks.
143
+-   Blocks can be passed around from method to method.
144
+
145
+
146
+
147
+# Closing
148
+
149
+
150
+
151
+-   Open IRB and ask questions.
152
+
153
+

+ 88
- 0
doc/plan.org View File

@@ -0,0 +1,88 @@
1
+#+title: Presentation Planning
2
+#+author: Peter Jones <pjones@devalot.com>
3
+#+startup: overview
4
+
5
+* Goals
6
+** 1-hour Presentation
7
+** 50% Lecture, 50% Action
8
+* Outline
9
+  :PROPERTIES:
10
+  :COLUMNS: %50ITEM(Task) %5Effort(Estimate){:}
11
+  :VISIBILITY: children
12
+  :END:
13
+** Introduction
14
+   :PROPERTIES:
15
+   :Effort:   02:00
16
+   :END:
17
+   - Ask questions at any time
18
+   - Your job is to understand
19
+   - My job is to keep us on time
20
+** 30-second History of Ruby
21
+   :PROPERTIES:
22
+   :Effort:   02:00
23
+   :END:
24
+   - First release: 1995
25
+   - Syntax influenced by Perl
26
+   - Features influenced by Smalltalk and Lisp
27
+   - Modern Ruby starts at 1.9 (2007)
28
+   - Several implementations, main is MRI
29
+** What is Ruby?
30
+   :PROPERTIES:
31
+   :Effort:   05:00
32
+   :END:
33
+   - Perl-flavored, C-like syntax (semicolons optional)
34
+   - Purely object-oriented
35
+   - Dynamically typed
36
+   - Garbage collected
37
+** Ruby Syntax
38
+   :PROPERTIES:
39
+   :Effort:   08:00
40
+   :END:
41
+   - Example Ruby code
42
+   - Naming scheme
43
+   - `begin` ... `end` vs. curly braces
44
+   - Implicit return value
45
+** Everything is an Object
46
+   :PROPERTIES:
47
+   :Effort:   05:00
48
+   :END:
49
+   - Open IRB:
50
+     - Play with numeric literals
51
+     - String literals: double quotes
52
+** Everything is an Expression
53
+   :PROPERTIES:
54
+   :Effort:   10:00
55
+   :END:
56
+   - Open IRB:
57
+     - Play with `if`
58
+     - String interpolation
59
+** Object-Oriented Programming
60
+   :PROPERTIES:
61
+   :Effort:   05:00
62
+   :END:
63
+   - Example code
64
+   - Single inheritance
65
+   - Emulated multiple inheritance through modules
66
+   - Modules *are not* interfaces.
67
+   - Variable names indicate their scope.
68
+** Everything is an Object (Part 2)
69
+   :PROPERTIES:
70
+   :Effort:   05:00
71
+   :END:
72
+   - `Array.class`
73
+** Blocks
74
+   :PROPERTIES:
75
+   :Effort:   15:00
76
+   :END:
77
+   - Example code (`Array#each`)
78
+   - Example code (`File::open`)
79
+   - Borrowed from Smalltalk
80
+   - Long form: `do |x|` ... `end`
81
+   - Short form `{|x| ...}`
82
+   - Alternative to deterministic destruction
83
+   - You can write methods which accept blocks
84
+** Closing
85
+   :PROPERTIES:
86
+   :Effort:   03:00
87
+   :END:
88
+   - Open Q&A in IRB

+ 127
- 2
slides.md View File

@@ -2,6 +2,131 @@
2 2
 % Peter Jones <pjones@devalot.com>
3 3
 %
4 4
 
5
-# Syntax Basics
5
+# Introduction
6 6
 
7
-Foo Bar.
7
+~~~ {.ruby include="src/intro.rb" token="intro"}
8
+~~~
9
+
10
+<div class="notes">
11
+
12
+  * Please ask questions at any time.
13
+  * Your job is to understand the material.
14
+  * My job is to keep us on track and on time.
15
+
16
+</div>
17
+
18
+# 30-second History of Ruby
19
+
20
+~~~ {.ruby include="src/intro.rb" token="in-30"}
21
+~~~
22
+
23
+  * When and where?
24
+  * Influences.
25
+  * "Modern" Ruby.
26
+
27
+<div class="notes">
28
+
29
+  * First released in 1995 by Japanese Programmer "Matz".
30
+  * Syntax influenced by Perl (C-style).
31
+  * Features influenced by Smalltalk and Lisp.
32
+  * Modern Ruby began with v1.9 (2007)
33
+  * Several Implementations, main is [MRI] [].
34
+
35
+</div>
36
+
37
+# What is Ruby?
38
+
39
+~~~ {.ruby include="src/what.rb" token="is_a"}
40
+~~~
41
+
42
+<div class="notes">
43
+
44
+  * Purely object-oriented.
45
+  * General purpose (not just web apps!)
46
+  * Dynamically typed.
47
+  * Garbage collected.
48
+
49
+</div>
50
+
51
+# Ruby Syntax
52
+
53
+~~~ {.ruby include="src/syntax.rb" token="person"}
54
+~~~
55
+~~~ {.ruby include="src/syntax.rb" token="new"}
56
+~~~
57
+
58
+<div class="notes">
59
+
60
+  * Perl-flavored, C-like syntax
61
+  * Semicolons are optional (line-based)
62
+  * Whitespace insignificant.
63
+  * Constants use CamelCase
64
+  * Variables and methods use snake_case.
65
+  * Blocks of code are delimited by `begin...end` or `do...end`.
66
+  * All methods return a value (no `void` functions).
67
+  * Implicit return of final value.
68
+  * The scope of a variable is determined by its name.
69
+
70
+</div>
71
+
72
+# Everything is an Object
73
+
74
+<div class="notes">
75
+
76
+  * Numeric literals are objects.
77
+  * String literals are objects.
78
+
79
+</div>
80
+
81
+# Everything is an Expression
82
+
83
+<div class="notes">
84
+
85
+  * An `if` statement is really an expression.
86
+  * Using `if` in string interpolation.
87
+  * Class definition is an expression.
88
+  * Method definition is an expression.
89
+
90
+</div>
91
+
92
+# Object-oriented Programming
93
+
94
+<div class="notes">
95
+
96
+  * Ruby only allows single inheritance.
97
+  * Multiple inheritance is emulated with modules.
98
+  * Modules *are not* interfaces.
99
+
100
+</div>
101
+
102
+# Everything is an Object (Part 2)
103
+
104
+<div class="notes">
105
+
106
+  * Even classes are objects!
107
+
108
+</div>
109
+
110
+# Blocks
111
+
112
+<div class="notes">
113
+
114
+  * Blocks are borrowed from Smalltalk.
115
+  * Blocks can be used as iterators (`Array#each`).
116
+  * And also for resource management (`File::open`).
117
+  * Long form: `do |x| ... end`.
118
+  * Short form: `{|x| ... }`.
119
+  * You can write methods which accept blocks.
120
+  * Blocks can be passed around from method to method.
121
+
122
+</div>
123
+
124
+# Closing
125
+
126
+<div class="notes">
127
+
128
+  * Open IRB and ask questions.
129
+
130
+</div>
131
+
132
+[mri]: http://www.ruby-lang.org

+ 41
- 0
src/intro.rb View File

@@ -0,0 +1,41 @@
1
+#!ruby -w
2
+
3
+################################################################################
4
+require('minitest/autorun')
5
+
6
+################################################################################
7
+class IntroTest < MiniTest::Unit::TestCase
8
+
9
+  ##############################################################################
10
+  # <<: intro
11
+  class You
12
+    def ask_questions
13
+      # ...
14
+    end
15
+  end
16
+
17
+  class Me
18
+    def keep_on_track
19
+      # ...
20
+    end
21
+  end
22
+  # :>>
23
+
24
+  ##############################################################################
25
+  def test_intro
26
+    assert(You.new.respond_to?(:ask_questions))
27
+    assert(Me.new.respond_to?(:keep_on_track))
28
+  end
29
+
30
+  ##############################################################################
31
+  def time_in_30
32
+    # <<: in-30
33
+    Time.now + 30 * 60
34
+    # :>>
35
+  end
36
+
37
+  ##############################################################################
38
+  def test_time
39
+    assert(time_in_30 > Time.now)
40
+  end
41
+end

+ 36
- 0
src/syntax.rb View File

@@ -0,0 +1,36 @@
1
+#!ruby -w
2
+
3
+################################################################################
4
+require('minitest/autorun')
5
+
6
+################################################################################
7
+class SyntaxTest < MiniTest::Unit::TestCase
8
+
9
+  ##############################################################################
10
+  # <<: person
11
+  class Person
12
+    def initialize (first, last)
13
+      @first_name = first
14
+      @last_name  = last
15
+    end
16
+
17
+    def name
18
+      @first_name + ' ' + @last_name
19
+    end
20
+  end
21
+  # :>>
22
+
23
+  ##############################################################################
24
+  def new_person
25
+    # <<: new
26
+    character = Person.new("Sheldon", "Cooper")
27
+    character.name
28
+    # :>>
29
+    character
30
+  end
31
+
32
+  ##############################################################################
33
+  def test_new_person
34
+    assert_equal("Sheldon Cooper", new_person.name)
35
+  end
36
+end

+ 32
- 0
src/what.rb View File

@@ -0,0 +1,32 @@
1
+#!ruby -w
2
+
3
+################################################################################
4
+require('minitest/autorun')
5
+
6
+################################################################################
7
+class WhatTest < MiniTest::Unit::TestCase
8
+
9
+  ##############################################################################
10
+  class Language; end
11
+
12
+  ##############################################################################
13
+  class Ruby < Language
14
+    def typing? (*) true; end
15
+    def memory? (*) true; end
16
+  end
17
+
18
+  ##############################################################################
19
+  def what
20
+    ruby = Ruby.new
21
+    # <<: is_a
22
+    ruby.is_a?(Language)     &&
23
+      ruby.typing?(:dynamic) &&
24
+      ruby.memory?(:gc)      # => true
25
+    # :>>
26
+  end
27
+
28
+  ##############################################################################
29
+  def test_what
30
+    assert(what)
31
+  end
32
+end

+ 1
- 1
vendor/devalot-slides

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

Loading…
Cancel
Save