Skip to content

Instantly share code, notes, and snippets.

@gouf
Created December 29, 2018 13:26
Show Gist options
  • Save gouf/35e2869496dc749014b20c0dfe8a4cfa to your computer and use it in GitHub Desktop.
Save gouf/35e2869496dc749014b20c0dfe8a4cfa to your computer and use it in GitHub Desktop.
Faker で適当な JSON データの生成
# frozen_string_literal: true
require 'faker'
require 'json'
result =
Array.new(100).map do |i|
gender = %w[Male Female].sample
first_name, last_name =
if gender.eql?('Male')
[Faker::Name.male_first_name, Faker::Name.last_name]
else
[Faker::Name.female_first_name, Faker::Name.last_name]
end
{
'id': i,
'firstName': first_name,
'lastName': last_name,
'gender': gender
}
end
puts result.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment