Problem with return from method

J

James Byrne

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 )
else
hash
end
puts( "I am returning from remap_current_hash" )
puts( "@current_hash is: " )
puts( @current_hash.to_yaml.sort )
puts()
return @current_hash
end

before the return in remap @current_hash looks like this:

@current_hash is:
- 7507PARS003936
---
:ccdns:
: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?
 
J

James Byrne

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top