module IRB

def set_encoding(extern, intern = nil, override: true)

def set_encoding(extern, intern = nil, override: true)
  verbose, $VERBOSE = $VERBOSE, nil
  Encoding.default_external = extern unless extern.nil? || extern.empty?
  Encoding.default_internal = intern unless intern.nil? || intern.empty?
  [$stdin, $stdout, $stderr].each do |io|
    io.set_encoding(extern, intern)
  end
  if override
    @CONF[:LC_MESSAGES].instance_variable_set(:@override_encoding, extern)
  else
    @CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern)
  end
ensure
  $VERBOSE = verbose
end