I'm a bit confused with the '£' symbol in Ruby.
In JRuby if I do :
puts '£40'
in a .rb file I run this, I get
£40
In JRuby IRB I get :
>> pung = 'h40'
=> "h40"
>开发者_C百科;> pung.gsub!('h', '£')
pung.gsub!('h', '£')
=> "\24340"
The pound symbol is output as \243.
In pure Ruby IRB, I cant even enter the £ symbol.. The cursor jumps to the left three spaces when I hit the £ key!
trying .toutf8 or toutf16 bring up even stranger characters!
Whats going on!??!? Why cant I just output a simple £?
Sometimes this is a problem with the way your console pastes the character. For example, the unicode character sequence may include a character the console uses to do backspace or arrow left. This is probably the issue with the IRB console not receiving your character ok.
For the script, it looks like JRuby's doing what it's supposed to. The issue with the console should probably be reported as a bug, however, since we do want IRB to support entering unicode characters. Pop over to JRuby's bug tracker at http://bugs.jruby.org and provide show a simple session or provide steps to reproduce (which should be easy).
Most likely, the symbol is a Unicode symbol and you are converting it (perhaps unintentionally). If you can't enter the pound sterling symbol, make sure your console supports Unicode.
What do you get when you do £.class
? String
? Unicode::String
? Perhaps explicitly declaring the character as a Unicode::String
or Unicode::Character
will give different results.
'\243' is the octal escape sequence for '£'.
精彩评论