Skip to content

Instantly share code, notes, and snippets.

@W-Mills
Last active December 16, 2018 19:58
Show Gist options
  • Save W-Mills/d52a23e35f0e793919b0e3289a47e785 to your computer and use it in GitHub Desktop.
Save W-Mills/d52a23e35f0e793919b0e3289a47e785 to your computer and use it in GitHub Desktop.
# recreation_centre_expanded.rb
module Swimmable
def swim
"Can swim here!"
end
end
class GreenSpace
attr_accessor :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
@@num_rec_centres = 0
def initialize(name, num_trees, philanthropist)
super(name, num_trees)
@philanthropist = philanthropist
@@num_rec_centres += 1
end
def whats_this
self
end
def self.num_rec_centres
@@num_rec_centres
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")
scadding_court = RecreationCentre.new("DunBat", 25, "Jim Balsillie")
RecreationCentre.num_rec_centres # => 2
scadding_court.name # => "DunBat"
scadding_court.name = "Scadding Court"
scadding_court.name # => "Scadding Court"
scadding_court.whats_this # => #<RecreationCentre:0x00007fc73b9a0060 @name="Scadding Court", @num_trees=25, @philanthropist="Jim Balsillie">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment