Who is this guy?
Steven! Ragnarök
contact = {
"GitHub" => "nuclearsandwich",
"Freenode" => "nuclearsandwich",
"Email" => "[email protected]",
"WWW" => "www.nuclearsandwich.com",
"Twitter" => "@nuclearsandwich"
}
''That guy with all the opinions''
Slide 3
Slide 3 text
Teaching
Programming
Slide 4
Slide 4 text
Why is teaching so
damn hard?
Slide 5
Slide 5 text
Why is teaching so
damn hard?
• It's hard to remember
learning to program
Slide 6
Slide 6 text
Why is teaching so
damn hard?
• It's hard to remember
learning to program
• It's hard to share
knowledge instead of
guard it
Slide 7
Slide 7 text
Why is teaching so
damn hard?
In short: it takes a lot of self
reflection to teach well.
Objects Have (a) Class
5.send :class
#=> Fixnum
4.0.send :class
#=> Float
["he's", "crazy?"].send :class
#=> Array
Slide 43
Slide 43 text
Teaching
Objects
The pen and the scribe
Slide 44
Slide 44 text
Instantiation
pen = Object.new
#=> #
Slide 45
Slide 45 text
Method Definition
def pen.to_s
"A trusty pen"
end
#=> nil
Slide 46
Slide 46 text
Message Sending
pen.send :to_s
#=> A trusty pen
Slide 47
Slide 47 text
A Pinch of Sugar
def pen.to_s
"A trusty pen"
end
pen.to_s
#=> A trusty pen
Slide 48
Slide 48 text
Errors Are Your Friends
pen.write "Hi there"
#=> NoMethodError: undefined
# method `write' for
# A trusty pen:Object
Slide 49
Slide 49 text
Use the Kernel, Luke
def pen.write thing
Kernel.puts thing
end
#=> nil
Slide 50
Slide 50 text
Write Anything!
pen.write "Hi"
Hi
#=> nil
pen.write pen
A trusty pen
#=> nil
Slide 51
Slide 51 text
Feature Request: Color
pen.ink_color = "Blue"
#=> NoMethodError: undefined
# method `ink_color=' for
# A trusty pen:Object
def pen.ink_color= color
@ink_color = color
end
#=> nil
Slide 52
Slide 52 text
Showing Our Colors
def pen.to_s
"A trusty #{@ink_color} pen"
end
pen.ink_color = "purple"
#=> "purple"
pen
#=> "A trusty purple pen"
Slide 53
Slide 53 text
Implicit Receivers
def pen.sparkly_write thing
write "*;. #{thing} *;.*"
end
pen.sparkly_write pen
*;. A trusty purple pen *;.*
Slide 54
Slide 54 text
Conditionals Revisited
def pen.html_write thing
write if @ink_color
"
#{thing}
"
else
"
#{thing}
"
end
end
Slide 55
Slide 55 text
Teaching
Ruby
What have we
introduced?
Slide 56
Slide 56 text
Time to get classy…
Scribe = Class.new do
def initialize pen
@pen = pen
@items = Array.new
end
def note item
@items.<< item
end
# to be continued
Slide 57
Slide 57 text
…you blockhead
# in the Scribe class body
def write_everything
@items.each do |item|
@pen.write item
end
end
end
#=> Scribe
Slide 58
Slide 58 text
Hiring a new scribe
mielot = Scribe.new pen
#=> #
mielot.note "Time: #{Time.now}"
mielot.note "This demo is over"
mielot.write_everything
Time: 2012-09-14 11:43:05 -0700
This demo is over
Slide 59
Slide 59 text
Teaching
Ruby
with Objects
Slide 60
Slide 60 text
Teaching
Objects
with Ruby
Slide 61
Slide 61 text
Why is this better?
The object metaphor provides
a context for everything else
we learn about Ruby
Slide 62
Slide 62 text
Why is this better?
We don't bombard them with
new concepts until just before
their use
Slide 63
Slide 63 text
Why is this better?
With a thorough understanding
of semantics, new things (like
syntactic sugar) are more
readily digestible
Slide 64
Slide 64 text
Thanks!
Behind the Scenes
X
E
L
A
TEX/ Beamer
Pygments / Minted