Skip to content

Instantly share code, notes, and snippets.

@Nursultan91
Created March 3, 2018 17:13
Show Gist options
  • Save Nursultan91/4289308a382c525a7aaaf738329590eb to your computer and use it in GitHub Desktop.
Save Nursultan91/4289308a382c525a7aaaf738329590eb to your computer and use it in GitHub Desktop.
class MovieCollection
FIELDS = %i[link title year country premiere genre duration rank director cast]
def initialize(filename)
@file = filename
end
def all
@@all = File.readlines(@file)
.map { |line| FIELDS.zip(line.split("|")).to_h }
end
def sort_by_the(argument)
@argument = argument.to_s
@sorted_collection = @@all.sort_by { |movie| movie[@argument].to_i }
puts @sorted_collection
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment