Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Improve #cell argument parsing to distinguish between multiple args and a single arg #9

merged 1 commit into from

3 participants


No description provided.


This pull request passes (merged cfb2813 into 5cb0d30).


@brendon I believe this should resolve your outstanding issue in #8

Now, whenever you call csv.cell with 2 arguments, that second argument is set as the cell value, even if it is (or evalutes to) nil

@paulspringett paulspringett merged commit 44d0519 into master

@brendon I've released version 0.2.0 which should fix your outstanding issue in #8


Thanks Paul, that's really great :) Good to close off that edge case as I think it could have caught others out, and it's very difficult to figure out the cause without looking at the code :)

Have a great day! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 22, 2012
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 5 deletions.
  1. +15 −5 lib/csv_shaper/row.rb
  2. +13 −0 spec/row_spec.rb
20 lib/csv_shaper/row.rb
@@ -57,13 +57,23 @@ def cells(*args)
# `value` - data to assign to the cell (default: nil)
# Returns an Array of the Row's cells
- def cell(column, value = nil)
- column = column.to_sym
+ def cell(*args)
+ if args.empty?
+ raise ArgumentError, 'no args passed to #cell, you must pass at least a column name'
+ end
+ column = args.first.to_sym
- if @model && @model.respond_to?(column) && value.nil?
- @cells[column] = @model.send(column)
+ if args.size == 2
+ @cells[column] = args.last
+ elsif args.size == 1
+ if @model && @model.respond_to?(column)
+ @cells[column] = @model.send(column)
+ else
+ raise ArgumentError, "##{column} is not a method on #{@model.class.to_s}, call `csv.cell #{column}, value` instead"
+ end
- @cells[column] = value
+ raise ArgumentError, 'you can pass a column or a column with a value to #cell'
13 spec/row_spec.rb
@@ -41,5 +41,18 @@
row.cell :foo, nil
row.cells.should eq({ foo: nil, gender: 'Male' })
+ it "should not send column to model if two args are passed" do
+ row =, :gender)
+ row.cell :name, 'Another name'
+ row.cells.should eq({ name: 'Another name', gender: 'Male' })
+ end
+ it "should raise an exception of the model does not respond to column, and no value is passed" do
+ row =, :gender)
+ expect {
+ row.cell :foo
+ }.to raise_error(ArgumentError)
+ end
Something went wrong with that request. Please try again.