Created
April 8, 2015 02:32
-
-
Save NevadaKiran/a1fcf8e1f3ebcea45922 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 Cup | |
attr_accessor :color, | |
:contents, | |
:lid | |
def initialize(contents = :empty) | |
puts self.object_id | |
@color = "blue" | |
@contents = contents | |
@lid = false | |
end | |
def contents? | |
contents != :empty | |
end | |
def empty! | |
self.contents = :empty | |
end | |
alias_method :empty_contents, :empty! | |
def empty_contents | |
empty | |
end | |
def lid? | |
lid | |
end | |
def to_s | |
"[cup] contents, #{contents}, color #{color}, lid #{lid}" | |
end | |
end | |
cup = Cup.new("juice") | |
puts cup | |
puts cup.inspect | |
puts cup.contents | |
puts "Has contents" if cup.contents? | |
puts cup.empty | |
puts cup.empty_contents | |
puts cup.color | |
puts cup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment