CSV To Ruby Array

Login

Email
Password

Don't have an account yet?

Go to Sign up

{{ workbook ? 'Online Table Editor' : 'Input Data' }}
Change File Enter Data
Row Col Row Col
Transpose Clear Delete Empty Deduplicate
ABC abc Abc
Replace
First Row as Header
{{ displayRows.length }} rows x {{ displayHeaders.length }} columns{{ firstRowAsHeader ? ' (1 header)' : '' }} {{ selectedRows.length > 0 ? selectedRows.length + ' selected' : '' }}
Output Data
{{ copied ? 'Copied!' : 'Copy to Clipboard' }} Download File
Properties
Convert CSV to Ruby online — paste, edit, and download Ruby.

Convert Restart
Insert Row Below
Insert Row Above
Insert Column Right
Insert Column Left
Delete Row {{ contextMenu.row + 1 }}
Delete Column {{ contextMenu.col + 1 }}
Clear Cell
Clear Row
Case sensitive Use regex Cancel Replace All

CSV to Ruby Array — Free Online Converter with Table Editor

What Is Ruby?

Ruby is a dynamic, object-oriented programming language created by Yukihiro Matsumoto in 1995. It is known for its elegant syntax, developer happiness, and the Ruby on Rails web framework.

Ruby Array and Hash Syntax

Arrays

# Array of strings

names = ["Alice", "Bob", "Charlie"]


# Array of integers

scores = [95, 88, 72]


# 2D array (array of arrays)

data = [

 ["Alice", 30, "New York"],

 ["Bob", 25, "London"]

]

Hashes

# Hash rocket syntax (all Ruby versions)

user = {"name" => "Alice", "age" => 30, "city" => "New York"}


# Symbol key syntax (Ruby 1.9+)

user = {name: "Alice", age: 30, city: "New York"}


# Mixed

config = {"api_key" => "abc123", timeout: 30}

Hash Rocket vs. Symbol Keys

StyleSyntaxWhen to Use
Hash rocket"key" => valueString keys from external data (CSV, JSON, APIs)
Symbol keyskey: valueInternal Ruby code, configuration, method options

For CSV-converted data, hash rocket syntax is more appropriate because CSV headers are strings, not symbols.

Why Convert CSV to Ruby Arrays?

Use CaseDescription
Test fixturesGenerate Ruby test data from CSV for RSpec or Minitest
Seed dataCreate Ruby seed files for Rails db/seeds.rb
ConfigurationEmbed CSV data as Ruby constants or configuration hashes
Data migrationConvert CSV exports to Ruby code for import scripts
Hardcoding dataEmbed static data directly in Ruby source instead of reading CSV files
PrototypingQuick data structure creation for Ruby scripts and irb sessions
Rails factoriesGenerate FactoryBot traits or custom factory data
Code golfCompact data representation in Ruby scripts

CSV.read vs. This Tool

Using CSV.read (Runtime)

require 'csv'data = CSV.read('data.csv', headers: true)data.each do |row|  puts row['name']end
AspectCSV.read
When to useDynamic CSV files that change at runtime
RequiresCSV file present at runtime
FlexibilityHandles any CSV at runtime
DependenciesRequires CSV file path

Using This Tool (Code Generation)

AspectThis Tool
When to useStatic data, test fixtures, seed files
OutputSelf-contained Ruby code
FlexibilityEditable Ruby source
DependenciesNone at runtime — data is embedded in code

Core Features

1. Online Table Editor

After loading CSV data, an interactive spreadsheet grid lets you edit before converting:

OperationDescription
TransposeSwap rows and columns
ClearRemove all data
Delete EmptyRemove empty rows/columns
DeduplicateRemove duplicate rows
ReplaceFind and replace (with regex support)
Case transformUPPERCASE, lowercase, Title Case
Insert/deleteRight-click for row/column operations
First Row as HeaderToggle header treatment

2. Privacy by Design

All processing runs entirely in your browser. No data is uploaded to any server.

How to Use This Tool — Step-by-Step

Step 1: Load CSV Data

Choose one of two input methods:

  • Upload a file: Click "Choose File" and select a .csv file.

  • Paste data: Click "Enter Data" to switch to the code editor. Paste your CSV.

Step 2: Edit in Table Editor (Optional)

Use the toolbar to clean your data:

  • Remove duplicates (Deduplicate)

  • Remove empty rows/columns (Delete Empty)

  • Find and replace values

  • Transform text case

  • Transpose rows and columns

Step 3: Convert

Click Convert. The Ruby code appears in the "Output Data" panel.

Step 4: Copy or Download

  • Click Copy to Clipboard to paste into your .rb file.

  • Premium users can click Download File to save.

Complete Example

Example — User Data

Input CSV:

name,age,city,active

Alice,30,New York,true

Bob,25,London,false

Charlie,35,Tokyo,true

Diana,28,Paris,true

Output:

[

 ["Alice", 30, "New York", "true"],

 ["Bob", 25, "London", "false"],

 ["Charlie", 35, "Tokyo", "true"],

 ["Diana", 28, "Paris", "true"]

]

Example — Rails Seed Data

Input CSV:

name,email,role

Alice,[email protected],admin

Bob,[email protected],editor

Charlie,[email protected],viewer

After converting, adapt for Rails seeds:

# db/seeds.rb

users = [

 {"name" => "Alice", "email" => "[email protected]", "role" => "admin"},

 {"name" => "Bob", "email" => "[email protected]", "role" => "editor"},

 {"name" => "Charlie", "email" => "[email protected]", "role" => "viewer"}

]

users.each do |user|

 User.create!(user)

end

Example — RSpec Test Fixture

Input CSV:

input,expected

"hello world","HELLO WORLD"

"Ruby","RUBY"

"",""

After converting:

# spec/string_utils_spec.rb

test_cases = [

 ["hello world", "HELLO WORLD"],

 ["Ruby", "RUBY"],

 ["", ""]

]

test_cases.each do |input, expected|

 it "converts '#{input}' to '#{expected}'" do

   expect(StringUtils.upcase(input)).to eq(expected)

 end

end

Example — Product Catalog

Input CSV:

sku,name,price,stock

LAPTOP-001,Pro Laptop,1299.99,45

PHONE-001,Smart Phone,699.99,120

TABLET-001,Air Tablet,499.99,0

Output:

[

 ["LAPTOP-001", "Pro Laptop", "1299.99", "45"],

 ["PHONE-001", "Smart Phone", "699.99", "120"],

 ["TABLET-001", "Air Tablet", "499.99", "0"]

]

Example — Transposed Data

Input CSV (metrics by quarter):

metric,q1,q2,q3,q4

revenue,1000000,1200000,1150000,1400000

customers,500,550,580,620

After clicking Transpose:

[

 ["metric", "revenue", "customers"],

 ["q1", "1000000", "500"],

 ["q2", "1200000", "550"],

 ["q3", "1150000", "580"],

 ["q4", "1400000", "620"]

]

Ruby CSV Processing Tips

Parse CSV at Runtime

require 'csv'

# Read with headers (returns CSV::Table)

data = CSV.read('data.csv', headers: true)

data.first['name']  # => "Alice"


# Read without headers (returns Array of Arrays)

data = CSV.read('data.csv')

data[0][0]  # => "Alice"


# Parse CSV string

data = CSV.parse("name,age\nAlice,30")

Convert Array to Hash

headers = ["name", "age", "city"]

rows = [

 ["Alice", 30, "New York"],

 ["Bob", 25, "London"]

]


# Array of hashes

hashes = rows.map { |row| headers.zip(row).to_h }

# => [{"name"=>"Alice", "age"=>30, "city"=>"New York"}, ...]


# Or using Hash[]

hashes = rows.map { |row| Hash[headers.zip(row)] }

Common Ruby Array Operations

data = [

 ["Alice", 30, "New York"],

 ["Bob", 25, "London"],

 ["Charlie", 35, "Tokyo"]

]


# Access

data[0]          # => ["Alice", 30, "New York"]

data[0][1]       # => 30

data.first       # => ["Alice", 30, "New York"]

data.last        # => ["Charlie", 35, "Tokyo"]

data.size        # => 3


# Filter

data.select { |row| row[1] > 28 }

# => [["Alice", 30, ...], ["Charlie", 35, ...]]


# Sort

data.sort_by { |row| row[1] }# => [["Bob", 25, ...], ["Alice", 30, ...], ["Charlie", 35, ...]]


# Map

data.map { |row| row[0] }# => ["Alice", "Bob", "Charlie"]


# Transform to hashes

headers = ["name", "age", "city"]

data.map { |row| headers.zip(row).to_h }

Frequently Asked Questions (FAQ)

  • Is this tool free?

    Yes. The CSV to Ruby Array converter is free to use. A Premium plan unlocks file downloads.

  • Does the tool upload my data to the server?

    No. All conversion happens locally in your browser using JavaScript. Your data never leaves your device.

  • What output format does the tool generate?

    The tool generates Ruby array literals — arrays of arrays, where each inner array represents one CSV row. Values are quoted as strings.

  • Can I get Ruby hashes instead of arrays?

    The tool outputs arrays. Convert to hashes in Ruby using headers.zip(row).to_h. See the "Convert Array to Hash" example above.

  • What is the difference between hash rocket and symbol keys?

    Hash rocket: {"key" => value} — string keys, appropriate for external data like CSV. Symbol keys: {key: value} — symbol keys, conventional for internal Ruby code. Use hash rocket for CSV-converted data.

  • Can I use this for Rails seed files?

    Yes. Convert your CSV, then wrap the output in Model.create!(...) calls in db/seeds.rb. See the Rails Seed Data example above.

  • Can I edit the data before converting?

    Yes. The built-in table editor lets you modify cells, transpose, deduplicate, find/replace, change case, and insert/delete rows and columns.

  • What CSV formats are supported?

    Standard CSV with comma delimiters. The first row can be used as column headers (enable "First Row as Header").

  • Is there a file size limit?

    The tool processes data entirely in your browser. Files up to 10 MB typically convert without issues on modern hardware.

  • Can I use this on mobile?

    Yes. The tool is responsive, though the table editor is best experienced on desktop.

Featured Tools

Featured tools that you might find useful.

Popular Tools

List of popular tools that users love and frequently use.

New Tools

The latest tools added to our collection, designed for you.

Topics

The tools grouped by topics to quickly find what you need.
Free online JSON to YAML converter. Paste JSON and get clean YAML output instantly. Supports block and flow array styles, configurable indent. No upload, 100% private.

JSON To YAML

Free online JSON to YAML converter. Paste JSON and get clean YAML output instantly. Supports block and flow array styles, configurable indent. No upload, 100% private.
Free online JSON to XML converter. Paste JSON and generate valid XML with custom root/row elements, CDATA, XML declaration, attribute mode, and encoding options. No upload, 100% private.

JSON To XML

Free online JSON to XML converter. Paste JSON and generate valid XML with custom root/row elements, CDATA, XML declaration, attribute mode, and encoding options. No upload, 100% private.
Free online Markdown to Excel converter. Paste or upload Markdown tables, edit data in a spreadsheet editor, and download as .xlsx — all in your browser, no file upload required.

Markdown To Excel

Free online Markdown to Excel converter. Paste or upload Markdown tables, edit data in a spreadsheet editor, and download as .xlsx — all in your browser, no file upload required.
Free online JSON to CSV converter. Paste or upload JSON data and get formatted CSV instantly — no upload, 100% private. Supports custom delimiters, UTF-8 BOM, and JSON code editor.

JSON To CSV

Free online JSON to CSV converter. Paste or upload JSON data and get formatted CSV instantly — no upload, 100% private. Supports custom delimiters, UTF-8 BOM, and JSON code editor.