Skip to content

Instantly share code, notes, and snippets.

@gabidavila
Created August 7, 2017 19:05
Show Gist options
  • Select an option

  • Save gabidavila/a6f9d5f245aefab4b862732a03fc661d to your computer and use it in GitHub Desktop.

Select an option

Save gabidavila/a6f9d5f245aefab4b862732a03fc661d to your computer and use it in GitHub Desktop.
class MyFile
attr_accessor :name, :size, :content, :extension
def initialize(args)
@name = args[:name]
@size = args[:size]
@content = args[:content]
@extension = args[:extension]
end
def edit(content)
@content = content
end
end
class Storage
attr_accessor :brand, :speed, :capacity, :files
def initialize(args)
@brand = args[:brand]
@speed = args[:speed]
@capacity = args[:capacity]
@files = args[:files] || []
end
def add_file(file)
@files << file
end
def used_space
@files.reduce(0) do |total_size, file|
total_size += file.size
end
end
end
class ImageFile < MyFile
end
class TextFile < MyFile
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment