Warning: variable $KCODE is no longer effective

This warning comes from accessing $KCODE. What should be used instead?

In particular, this snippet from RDoc:

@charset = case $KCODE
when /^S/i
‘Shift_JIS’
when /^E/i
‘EUC-JP’
else
‘iso-8859-1’
end

Eventually @charset is placed in a in the output
RDoc. Is there a better way to determine the charset of a file?