Q:

Change Ruby Hash Value from Given Cucumber Table

I'm passing a table from cucumber into Ruby, trying to change a hash value, then I want to pass that table on to the next step.  The hash value changes, but the table is unaffected.  I'm doing something wrong, or missing some concept here.  Please advise!
My Example Cucumber:
Scenario:  Change Table Value
  Given I start with this table
  | person | grade |
  | Bob    | 82    |
  | Jim    | 94    |
  | Bill   | 58    |

Here's the Ruby:
Given /^I start with this table$/ do |table|
  puts "table is:"
  puts table
  table.hashes.each do |hash|
    puts "hash is:"
    puts hash

    puts "hash['person'] = #{hash['person']}"
    puts "assigning new name..."
    hash['person'] = 'Superman'
    puts "hash['person'] = #{hash['person']}"

    puts "hash is:"
    puts hash
  end
  puts "table is:"
  puts table
end

The output shows that the hash value is indeed changed, but the final puts of the table shows the original table is not affected.
I want to pass that table on to the next step as input with the new value.
Any advice would be appreciated,
Thanks,
Ed

A:

You can set the transformed table as an instance variable for the next step to read:
Given /^I start with this table$/ do |table|
  @hashes = []
  table.hashes.each do |hash|
    hash['person'] = 'Superman'
    @hashes << hash
  end
end

Then /^I can read the transformed data$/ do
  @hashes.each do |hash|
    puts hash
  end
end

