Problem with return from method

I have this situation arising in a single class:

method 1 contains:
. . .
current_hash = remap_current_hash( ao_hash )
puts( “I have returned from remap_current_hash” )
puts( “and now @current_hash contains:” )
puts( @current_hash.to_yaml.sort )
. . .

method remap_current_hash contains
def remap_current_hash( hash )
@current_hash = case
when hash.has_key?( :ao_cctn )
remap_ao_hash( hash )
when hash.has_key?( :rr_cctn )
remap_rr_hash( hash )
when hash.has_key?( :rs_cctn )
remap_rs_hash( hash )
puts( “I am returning from remap_current_hash” )
puts( "@current_hash is: " )
puts( @current_hash.to_yaml.sort )
return @current_hash

before the return in remap @current_hash looks like this:

 @current_hash is:
  - 7507PARS003936
  :cctn: "13466600016385"
  :cfia_facsimile_no: "          "
  :cfia_telephone_no: "          "
  :dollar_value_total: "00000000030736"
  :entry_type_code: AB
  :expected_at: "201006101300"
  .  .  .

immediately after the return it looks like this:
I have returned from remap_current_hash
and now @current_hash contains:
— “13466600016294”

Before the return, @current_hash is a hash. After the return it is a
string with a totally unexpected value. There is absolutely no
intermediate processing that I can do between the method return and the
local variable. What is happening here? What is doing this?

Found the error. I was not explicitly returning the remapped hash as a
hash when adding a key. Only the key value of the new key was returned
as it was the last operation before returning from that method.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs