Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8838125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:54:35+00:00 2026-06-14T09:54:35+00:00

I am trying to run a ruby script that uses inside a function that

  • 0

I am trying to run a ruby script that uses inside a function that removes diacritics:

def remove_diacritics(text)
return text.tr!(
"ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž",
"AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz")
end

I have the magic # encoding: utf-8 at the beginning and I am getting some strange behaviour. It works on Mac but when I copy exactly the same file to Raspberry Pi, I am getting this error:

remove_diacritics.rb:28:in `tr!’: incompatible character encodings: US-ASCII and UTF-8 (Encoding::CompatibilityError)

This seems to be a classic in help forums. The mesmerising thing is that it does work on one machine and doesn’t on the other one, even though the versions of Ruby are exactly the same, ruby 1.9.3p286 (2012-10-12 revision 37165).

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:54:37+00:00Added an answer on June 14, 2026 at 9:54 am

    It’s as Frederick points out. The (en)coding: comment determines the source encoding, but the error is caused by a mismatch with the external encoding. Your code produces CompatibilityError when run as

    LANG=C ruby encoding.rb
    

    but works with either of these

    LANG=cs_CZ@UTF-8 ruby         encoding.rb
    LANG=C           ruby -EUTF-8 encoding.rb
    

    See Ruby 1.9’s Three Default Encodings, a part of a great series explaining the Unicode situation in Ruby 1.8 and 1.9.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run a ruby script that parses a text file with
I have two ruby script cron jobs that I'm trying to run under Ubuntu
I'm trying to run a Ruby script using rbenv with cron. I know that
I'm trying to run on my mac os 10.6 a Ruby script that apparently
I've been having real problems trying to get a ruby script to run through
I'm trying to run a ruby file that will show git version of a
I have a Ruby script that I built in TextMate and can successfully run
I am running a ruby script that uses Ruby/MySQL and net/ftp. The script is
I am trying to run a ruby script which needs root access for some
I keep having this problem when trying to run inside directory that has server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.