Skip to content

Instantly share code, notes, and snippets.

@gnarg
Created October 30, 2012 20:34
Show Gist options
  • Save gnarg/3982829 to your computer and use it in GitHub Desktop.
Save gnarg/3982829 to your computer and use it in GitHub Desktop.
odd behavior of String#tr when applied to single characters
irb(main):018:0> RUBY_ENGINE
=> "jruby"
irb(main):019:0> RUBY_VERSION
=> "1.9.3"
irb(main):020:0> JRUBY_VERSION
=> "1.7.0"
irb(main):027:0> 'x'.tr('x', '_') # correct
=> "_"
irb(main):028:0> 'x'.tr('^x', '_') # incorrect
=> "_"
irb(main):030:0> 'xx'.tr('x', '_') # correct
=> "__"
irb(main):029:0> 'xx'.tr('^x', '_') # correct
=> "xx"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment