RudyGems

Matthew Rudy Jacobs
see me swim
Github
see some of my code
Thought Sauce
Hire me in Hong Kong

Ruby in Chinese

in Ruby 1.8, if you try and assign a variable

你=”ni3”

you’ll get an error

Invalid char `\344’ in expression
Invalid char `\275’ in expression
Invalid char `\240’ in expression
syntax error, unexpected ‘=’
你= “ni3”

But in Ruby 1.9 it actually works.

You just need to add a magic “coding: uft-8” header to your ruby file.

# coding: utf-8
你= “ni3”
好= “hao3”
puts(你+好)

Wham!

matthew@RuPro:~$ ruby chinese.rb
ni3hao3

(if you can’t write chinese, steal my gist http://gist.github.com/613670)