PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Languages/Ruby/Tests/Experiments/Regex/gsub.rb

http://github.com/IronLanguages/main
Ruby | 28 lines | 20 code | 8 blank | 0 comment | 2 complexity | a2d15a5cad14d434a164d693bd383b9c MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. x = "foo"
  2. p x.gsub(/(o)/, '1')
  3. p $1
  4. r = x.gsub!(/a/) { break '2' }
  5. p r.object_id == x.object_id
  6. r = x.gsub(/a/) { break '2' }
  7. p r.object_id == x.object_id
  8. p r
  9. p $1
  10. x = "foo"
  11. x.freeze
  12. x.gsub!(/a/) { '2' }
  13. x.gsub!(/a/, '2') rescue p ($!).class
  14. puts '---'
  15. begin
  16. x.gsub!(/o/) { '2' }
  17. rescue
  18. p $!.class
  19. end
  20. x.gsub!(/o/, '2') rescue p ($!).class