Go to Sign up
Note: Your files never leave your device. We don't upload, transfer, or store your data.
|
|
|
|
|---|---|---|
|
|
|
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.
# 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"]
]
# 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}
| Style | Syntax | When to Use |
|---|---|---|
| Hash rocket | "key" => value | String keys from external data (CSV, JSON, APIs) |
| Symbol keys | key: value | Internal Ruby code, configuration, method options |
For CSV-converted data, hash rocket syntax is more appropriate because CSV headers are strings, not symbols.
| Use Case | Description |
|---|---|
| Test fixtures | Generate Ruby test data from CSV for RSpec or Minitest |
| Seed data | Create Ruby seed files for Rails db/seeds.rb |
| Configuration | Embed CSV data as Ruby constants or configuration hashes |
| Data migration | Convert CSV exports to Ruby code for import scripts |
| Hardcoding data | Embed static data directly in Ruby source instead of reading CSV files |
| Prototyping | Quick data structure creation for Ruby scripts and irb sessions |
| Rails factories | Generate FactoryBot traits or custom factory data |
| Code golf | Compact data representation in Ruby scripts |
require 'csv'data = CSV.read('data.csv', headers: true)data.each do |row| puts row['name']end| Aspect | CSV.read |
|---|---|
| When to use | Dynamic CSV files that change at runtime |
| Requires | CSV file present at runtime |
| Flexibility | Handles any CSV at runtime |
| Dependencies | Requires CSV file path |
| Aspect | This Tool |
|---|---|
| When to use | Static data, test fixtures, seed files |
| Output | Self-contained Ruby code |
| Flexibility | Editable Ruby source |
| Dependencies | None at runtime — data is embedded in code |
After loading CSV data, an interactive spreadsheet grid lets you edit before converting:
| Operation | Description |
|---|---|
| Transpose | Swap rows and columns |
| Clear | Remove all data |
| Delete Empty | Remove empty rows/columns |
| Deduplicate | Remove duplicate rows |
| Replace | Find and replace (with regex support) |
| Case transform | UPPERCASE, lowercase, Title Case |
| Insert/delete | Right-click for row/column operations |
| First Row as Header | Toggle header treatment |
All processing runs entirely in your browser. No data is uploaded to any server.
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.
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
Click Convert. The Ruby code appears in the "Output Data" panel.
Click Copy to Clipboard to paste into your .rb file.
Premium users can click Download File to save.
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"]
]
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
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
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"]
]
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"]
]
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")
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)] }
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 }
Yes. The CSV to Ruby Array converter is free to use. A Premium plan unlocks file downloads.
No. All conversion happens locally in your browser using JavaScript. Your data never leaves your device.
The tool generates Ruby array literals — arrays of arrays, where each inner array represents one CSV row. Values are quoted as strings.
The tool outputs arrays. Convert to hashes in Ruby using headers.zip(row).to_h. See the "Convert Array to Hash" example above.
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.
Yes. Convert your CSV, then wrap the output in Model.create!(...) calls in db/seeds.rb. See the Rails Seed Data example above.
Yes. The built-in table editor lets you modify cells, transpose, deduplicate, find/replace, change case, and insert/delete rows and columns.
Standard CSV with comma delimiters. The first row can be used as column headers (enable "First Row as Header").
The tool processes data entirely in your browser. Files up to 10 MB typically convert without issues on modern hardware.
Yes. The tool is responsive, though the table editor is best experienced on desktop.