class Cucumber::Core::Test::DataTable


This will store [['a', 'b'], ['c', 'd']] in the data variable.
end
data = table.raw
Given /I have:/ do |table|
And a matching StepDefinition:
| c | d |
| a | b |
Given I have:
For example:
in different ways.
table parsed from a feature file and lets you access and manipulate the data
will receive it as an instance of DataTable. A DataTable object holds the data of a
Step Definitions that match a plain text Step with a multiline argument table

def ==(other)

def ==(other)
  other.class == self.class && raw == other.raw
end

def data_table?

def data_table?
  true
end

def describe_to(visitor, *args)

def describe_to(visitor, *args)
  visitor.data_table(self, *args)
end

def doc_string?

def doc_string?
  false
end

def dup


Creates a copy of this table
def dup
  self.class.new(raw.dup)
end

def ensure_array_of_array(array)

def ensure_array_of_array(array)
  Hash === array[0] ? hashes_to_array(array) : array
end

def hashes_to_array(hashes)

def hashes_to_array(hashes)
  header = hashes[0].keys.sort
  [header] + hashes.map {|hash| header.map {|key| hash[key]}}
end

def initialize(rows)


it internally and pass them to your Step Definitions.
You don't typically create your own DataTable objects - Cucumber will do
or an Array of Hash
Creates a new instance. +raw+ should be an Array of Array of String
def initialize(rows)
  raw = ensure_array_of_array(rows)
  verify_rows_are_same_length(raw)
  @raw = raw.freeze
end

def inspect

def inspect
  %{#<#{self.class} #{raw.inspect})>}
end

def lines_count

def lines_count
  raw.count
end

def map(&block)

def map(&block)
  new_raw = raw.map do |row|
    row.map(&block)
  end
  self.class.new(new_raw)
end

def to_step_definition_arg

def to_step_definition_arg
  dup
end

def transpose


| 4 | 2 |
| 7 | 9 |
| a | b |

Gets converted into the following:

| b | 9 | 2 |
| a | 7 | 4 |

Returns a new, transposed table. Example:
def transpose
  self.class.new(raw.transpose)
end

def verify_rows_are_same_length(raw)

def verify_rows_are_same_length(raw)
  begin
    raw.transpose
  rescue IndexError
    raise ArgumentError, "Rows must all be the same length"
  end
end