The check for opts[:open_args] needs to be there instead of open_args since we can use the encoding passed from opts[:open_args], also if I check for open_args && open_args[:encoding], that will always be true (from line 177 which has a ||) , so it will never go to the else part.

Regarding to checking for opts[:open_args], I agree it can be removed