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

Language Ruby Lines 29
MD5 Hash a2d15a5cad14d434a164d693bd383b9c Estimated Cost $444 (why?)
Repository git://github.com/IronLanguages/main.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
x = "foo"
p x.gsub(/(o)/, '1')
p $1

r = x.gsub!(/a/) { break '2' }
p r.object_id == x.object_id
r = x.gsub(/a/) { break '2' }
p r.object_id == x.object_id
p r

p $1

x = "foo"
x.freeze

x.gsub!(/a/) { '2' } 
x.gsub!(/a/, '2') rescue p ($!).class


puts '---'

begin
  x.gsub!(/o/) { '2' } 
rescue 
  p $!.class
end  

x.gsub!(/o/, '2') rescue p ($!).class
Back to Top