Skip to content

Instantly share code, notes, and snippets.

@NevadaKiran
Created April 8, 2015 02:32
Show Gist options
  • Save NevadaKiran/a1fcf8e1f3ebcea45922 to your computer and use it in GitHub Desktop.
Save NevadaKiran/a1fcf8e1f3ebcea45922 to your computer and use it in GitHub Desktop.
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