Question

I'm using a Ruby 1.8 lib kakasi-ruby, but it seems that it can only be compiled against Ruby 1.8 (https://github.com/hogelog/kakasi-ruby/issues/2)

My application is Ruby 1.9.3, so I need to call kakasi-ruby from Ruby 1.9.3.

How should I do?

Do I have to open a subprocess with Ruby 1.8, and wait for it finish to get the process return value?

Edit: https://github.com/hogelog/kakasi-ruby

Was it helpful?

Solution

Found 3 possible paths:

  • There seems to be a branch for 1.9 in the repo. Maybe try to compile that instead?
  • Otherwise your fastest option is probably to go back to 1.8 depending on what kind of app it is.
  • Calling with 1.8 may work BUT since the library seems to be a binding to some C code you could probably call that code directly just as well.

OTHER TIPS

BTW, here is the usage in Ruby 1.9

plee@sos:~/Japanese$ irb
1.9.3p194 :001 > require 'kakasi'
 => true 
1.9.3p194 :002 > src="前原誠司経済財政相は4日、朝日新聞などのインタビューに対し"
 => "前原誠司経済財政相は4日、朝日新聞などのインタビューに対し" 
1.9.3p194 :003 > src=src.encode("EUC-JP", "UTF-8")
 => "\x{C1B0}\x{B8B6}\x{C0BF}\x{BBCA}\x{B7D0}\x{BAD1}\x{BAE2}\x{C0AF}\x{C1EA}\x{A4CF}\x{A3B4}\x{C6FC}\x{A1A2}\x{C4AB}\x{C6FC}\x{BFB7}\x{CAB9}\x{A4CA}\x{A4C9}\x{A4CE}\x{A5A4}\x{A5F3}\x{A5BF}\x{A5D3}\x{A5E5}\x{A1BC}\x{A4CB}\x{C2D0}\x{A4B7}" 
1.9.3p194 :004 > dst=Kakasi.kakasi("-w", src)
 => "\xC1\xB0\xB8\xB6 \xC0\xBF\xBB\xCA \xB7\xD0\xBA\xD1 \xBA\xE2\xC0\xAF \xC1\xEA \xA4\xCF \xA3\xB4 \xC6\xFC \xA1\xA2 \xC4\xAB\xC6\xFC\xBF\xB7\xCA\xB9 \xA4\xCA\xA4\xC9\xA4\xCE \xA5\xA4\xA5\xF3\xA5\xBF\xA5\xD3\xA5\xE5\xA1\xBC \xA4\xCB \xC2\xD0\xA4\xB7" 
1.9.3p194 :005 > dst.force_encoding("EUC-JP")
 => "\x{C1B0}\x{B8B6} \x{C0BF}\x{BBCA} \x{B7D0}\x{BAD1} \x{BAE2}\x{C0AF} \x{C1EA} \x{A4CF} \x{A3B4} \x{C6FC} \x{A1A2} \x{C4AB}\x{C6FC}\x{BFB7}\x{CAB9} \x{A4CA}\x{A4C9}\x{A4CE} \x{A5A4}\x{A5F3}\x{A5BF}\x{A5D3}\x{A5E5}\x{A1BC} \x{A4CB} \x{C2D0}\x{A4B7}" 
1.9.3p194 :006 > dst=dst.encode("UTF-8", "EUC-JP")
 => "前原 誠司 経済 財政 相 は 4 日 、 朝日新聞 などの インタビュー に 対し" 
1.9.3p194 :007 > 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top