max
max

Reputation: 101811

IRB escapes UTF characters

I'm using OS-X (10.10.5) and rbenv (1.0.0) Ruby (2.2.4p230) and Fish Shell (2.2.0).

When I type non ASCII characters in irb they are automatically escaped.

max@MaxBook ~/p/sandbox> echo "Ö"
Ö
max@MaxBook ~/p/sandbox> irb 
irb(main):001:0> \U+FFC3\U+FFB6

I though at first this could be a problem with the shell or my Terminal settings but it only happens in IRB. Changing shells or ruby versions does not effect it.

I did not have this problem on my previous laptop which had an almost identical configuration. What is going on here?

Upvotes: 1

Views: 322

Answers (1)

spickermann
spickermann

Reputation: 106782

You can enable unicode support in IRB by recompiling Ruby against readline (instead of libedit which would be the default).

First install readline for example with brew:

brew install readline

I use rbenv to manage Ruby versions and use the following line to install Ruby versions:

RUBY_CONFIGURE_OPTS=--with-readline-dir="$(brew --prefix readline)" rbenv install 2.3.1

With rvm it will look like:

rvm install 2.3.1 --with-readline-dir=$rvm_path/usr

Or when you might want to recompile Ruby from source, then this answer might help you.

Upvotes: 3

Related Questions