Last active
November 17, 2015 05:08
-
-
Save kkchu791/78862590d345ffabf0f2 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
class Rectangle | |
attr_reader :area, :perimeter | |
def initialize(width, height) | |
@area = width * height | |
@perimeter = (width + height)*2 | |
end | |
end | |
r = Rectangle.new(23.45, 34.67) | |
puts "Area is = #{r.area}" | |
puts "Perimeter is = #{r.perimeter}" | |
#What if we change the instance variables to be area and perimeter, rather than width and length? What benefits does this give us? | |
#Shorter code and dimensions of rectangle are not exposed to modification. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment