Last active
December 16, 2018 19:58
-
-
Save W-Mills/5e2f366b4ec07da94b9f62f7f0174bba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# recreation_centre.rb | |
module Swimmable | |
def swim | |
"Can swim here!" | |
end | |
end | |
class GreenSpace | |
attr_reader :name, :num_trees | |
def initialize(name, num_trees) | |
@name = name | |
@num_trees = num_trees | |
end | |
end | |
class CityPark < GreenSpace; end | |
class RecreationCentre < CityPark | |
attr_reader :philanthropist | |
include Swimmable | |
def initialize(name, num_trees, philanthropist) | |
super(name, num_trees) | |
@philanthropist = philanthropist | |
end | |
end | |
class Forest < GreenSpace; end | |
class Lake < Forest | |
include Swimmable | |
end | |
dufferin_park = CityPark.new("Dufferin Park", 2000) | |
wallace_emerson = RecreationCentre.new("Wallace Emerson", 2, "Joe Beef") | |
dufferin_park.num_trees # => 2000 | |
wallace_emerson.num_trees # => 2 | |
wallace_emerson.swim # => "Can swim here!"" | |
dufferin_park.swim # NoMethodError => undefined method 'swim' for CityPark... | |
wallace_emerson.philanthropist # => "Joe Beef" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment