D
Daniel Moore
-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-
The three rules of Ruby Quiz:
1. Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have elapsed from the time this message was
sent.
2. Support Ruby Quiz by submitting ideas and responses
as often as you can!
Visit: http://rubyquiz.strd6.com/suggestions
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby Talk follow the discussion. Please reply to
the original quiz message, if you can.
RSS Feed: http://rubyquiz.strd6.com/quizzes.rss
-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-
## Prototype-Based Inheritance (#214)
Ay=FA Rubyists,
This week's quiz is to implement prototype-based Inheritance[1]. In
prototype-based inheritance objects gain their properties from other
objects, not from class hierarchies. Here's a code example to
illustrate setting a prototype explicitly:
pele =3D {:name =3D> "Pele", :sport =3D> "football", osition =3D> "Fo=
rward"}
pele_jr =3D {:name =3D> "Pele Jr."}
pele_jr.prototype =3D pele
pele_jr.name # =3D> "Pele Jr."
pele_jr.sport # =3D> "football"
pele_jr.position # =3D> "forward"
You may notice that this doesn't work: `NoMethodError: undefined
method 'prototype' for {:name =3D> "Pele", :sport =3D> "football",
osition =3D> "Forward"}:Hash`. If it did work then there's not much
for you to do on this quiz!
Hopefully this example illustrates some of the basics of how
prototype-based inheritance works: there is one prototypical football
player and other players defer to that player if they are queried for
an attribute that hasn't been specified. This relates closely with our
intuitions and how we discuss things "it's kind of like Starbucks,
except the drinks are bigger"
new_coffee_shop.prototype =3D starbucks
new_coffee_shop.drink_size +=3D 1
Have Fun!
[1]: http://en.wikipedia.org/wiki/Prototype-based_programming
--=20
-Daniel
http://rubyquiz.strd6.com
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-
The three rules of Ruby Quiz:
1. Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have elapsed from the time this message was
sent.
2. Support Ruby Quiz by submitting ideas and responses
as often as you can!
Visit: http://rubyquiz.strd6.com/suggestions
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby Talk follow the discussion. Please reply to
the original quiz message, if you can.
RSS Feed: http://rubyquiz.strd6.com/quizzes.rss
-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-
## Prototype-Based Inheritance (#214)
Ay=FA Rubyists,
This week's quiz is to implement prototype-based Inheritance[1]. In
prototype-based inheritance objects gain their properties from other
objects, not from class hierarchies. Here's a code example to
illustrate setting a prototype explicitly:
pele =3D {:name =3D> "Pele", :sport =3D> "football", osition =3D> "Fo=
rward"}
pele_jr =3D {:name =3D> "Pele Jr."}
pele_jr.prototype =3D pele
pele_jr.name # =3D> "Pele Jr."
pele_jr.sport # =3D> "football"
pele_jr.position # =3D> "forward"
You may notice that this doesn't work: `NoMethodError: undefined
method 'prototype' for {:name =3D> "Pele", :sport =3D> "football",
osition =3D> "Forward"}:Hash`. If it did work then there's not much
for you to do on this quiz!
Hopefully this example illustrates some of the basics of how
prototype-based inheritance works: there is one prototypical football
player and other players defer to that player if they are queried for
an attribute that hasn't been specified. This relates closely with our
intuitions and how we discuss things "it's kind of like Starbucks,
except the drinks are bigger"
new_coffee_shop.prototype =3D starbucks
new_coffee_shop.drink_size +=3D 1
Have Fun!
[1]: http://en.wikipedia.org/wiki/Prototype-based_programming
--=20
-Daniel
http://rubyquiz.strd6.com