find the people in your database whose ages are between 20 and 40: : csv « Development « Ruby






find the people in your database whose ages are between 20 and 40:


require 'csv'
people = CSV.read('text.txt')

young_people = people.find_all do |p|
  p[3].to_i.between?(20, 40)
end
puts young_people.inspect



//File: text.txt
F,M,M,45
L,C,F,23
D,P,F,38

 








Related examples in the same category

1.Read CSV file
2.Update a CSV file
3.Parse one CSV file line
4.Create data for CSV file
5.Reading and Searching CSV Data
6.use CSV alongside the File class
7.loading the data from a CSV-formatted file into an array is with CSV.read:
8.pick out the first person in the data called Laura:
9.Saving Data Back to the CSV File