Last active
December 16, 2018 19:57
-
-
Save W-Mills/b4af795bc6968f7d430cb7b3e2189af7 to your computer and use it in GitHub Desktop.
Ruby OOP Basics article
This file contains 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
#city_park.rb | |
class CityPark | |
attr_reader :name, :num_trees | |
def initialize(name, num_trees) | |
@name = name | |
@num_trees = num_trees | |
end | |
end | |
class Forest | |
attr_reader :name, :num_trees | |
def initialize(name, num_trees) | |
@name = name | |
@num_trees = num_trees | |
end | |
end | |
high_park = CityPark.new("High Park", 5000) | |
durham_forest = Forest.new("Durham Forest", 125000) | |
dufferin_park = CityPark.new("Dufferin Park", 2000) | |
high_park.name # => "High Park" | |
high_park.num_trees # => 5000 | |
durham_forest.name # => "Durham Forest" | |
durham_forest.num_trees # => 125000 | |
dufferin_park.num_trees # => 2000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment