-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

## Prototype-Based Inheritance (#214)

AyRubyists,

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 = {:name => "Pele", :sport => "football", :position => "Forward"}
    pele_jr = {:name => "Pele Jr."}
    pele_jr.prototype = pele
    pele_jr.name # => "Pele Jr."
    pele_jr.sport # => "football"
    pele_jr.position # => "forward"

You may notice that this doesn't work: `NoMethodError: undefined
method 'prototype' for {:name => "Pele", :sport => "football",
:position => "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 = starbucks
    new_coffee_shop.drink_size += 1

Have Fun!

[1]: http://en.wikipedia.org/wiki/Prototype-based_programming

-- 
-Daniel
http://rubyquiz.strd6.com