You can see the environment with the following Ruby snippet:
Code:
ENV.each do |key,value| puts "#{key} = #{value}"; end
You'll see there are entries for "USER" and "USERNAME" -- the former is the one you'll want to check for the sake of confirming permissions. If the script is run through sudo, "USER" will be the sudo-ed-to user (usually root) and "USERNAME" will be the user who ran sudo. (Of course, sudo sets other environment variables, but I presume that "USERNAME" would reveal the original UID of other programs that change permissions during the course of execution as well.)
Oh, also, ENV is a hash, in case that wasn't apparent. ENV["USER"] gets the value.