I am trying to remove a Silverware class inside of the @contents array by rewriting the method "remove_item" inside the drawer class. This method should takes a parameter of the name of the @type of the silverware.
class Drawer
attr_reader :contents
def initialize
@contents = []
end
def add_item(item)
@contents << item
end
def remove_item(item = @contents.pop)
@contents.delete(item) # I have to fix this.
end
end
class Silverware
attr_reader :type
def initialize(type, clean = true)
@type = type
end
end
silverware_drawer = Drawer.new # creating new drawer
silverware_drawer.add_item(Silverware.new("spoon")) # adding silverware
p silverware_drawer.contents # I get this >> [#<Silverware:0x007f84aa091ad8 @type="spoon", @clean=true>]
p silverware_drawer.remove_item("spoon") # removing spoon
p silverware_drawer.contents # Show drawer and I still get [#<Silverware:0x007f84aa091ad8 @type="spoon", @clean=true>]
Any helps would be greatly appreciated! Thank you in advance!