whoami
Amir Friedman
● Developer at DaWanda (we’re hiring!)
● Vegetarian
● [email protected]
● @NewArtRiot
● http://github.com/psychocandy
Slide 3
Slide 3 text
What is “Meta Programming”?
Slide 4
Slide 4 text
“Code that treats code as data”
Slide 5
Slide 5 text
“Anything that
would blow the
mind of a Java
developer”
Slide 6
Slide 6 text
“Code that writes code”
Slide 7
Slide 7 text
“There is no such thing as MP,
there’s just programming”
Slide 8
Slide 8 text
What are we going to learn
● Clear uncertainty regarding MP
● Show different layers of MP
● Make you feel secure about MP
● Show examples from the real-world
Slide 9
Slide 9 text
Some Basic Concepts
● Method manipulation
● Class definition
● Module definition
● Mixin
Slide 10
Slide 10 text
The Ruby Ancestors Chain
Let’s open pry (irb)!
> self.class.ancestors
=> [Object, PP::ObjectMixin, Kernel, BasicObject]
> class Greeting ; end
> Greeting.ancestors
=> ?
> module Hello ; end
...
Slide 11
Slide 11 text
Ancestors Chain
class Greeting
if rand(2) == 0
include X
else
include Y
end
end
We redirect messages during runtime :)