B
Brian Candler
If I assign a new value to $0, I find it is truncated.
$ cat test-dollar0.rb
puts $0
str = "/foo" * 20
puts str.size
$0 = str
puts $0
puts $0.size
$ ruby test-dollar0.rb
test-dollar0.rb
80
/foo/foo/foo/foo/foo
20
$ ln -s test-dollar0.rb td.rb
$ ruby td.rb
td.rb
80
/foo/foo/f
10
In 1.8.6 I can get around this by $0.replace('....'), which sets $0 to
any string I like. However this doesn't work in 1.8.7 or 1.9, because in
those versions $0 is a frozen string.
Any suggestions for how to fix this? The application is that I want to
start launcher program A, which in turn loads program B. Program B may
be a Test::Unit test suite, and Test::Unit gets the test suite name from
$0. So I either end up with the test suite having the name of program A
(which is wrong), or a truncated version of program B's name (which is
also wrong)
Thanks,
Brian.
$ cat test-dollar0.rb
puts $0
str = "/foo" * 20
puts str.size
$0 = str
puts $0
puts $0.size
$ ruby test-dollar0.rb
test-dollar0.rb
80
/foo/foo/foo/foo/foo
20
$ ln -s test-dollar0.rb td.rb
$ ruby td.rb
td.rb
80
/foo/foo/f
10
In 1.8.6 I can get around this by $0.replace('....'), which sets $0 to
any string I like. However this doesn't work in 1.8.7 or 1.9, because in
those versions $0 is a frozen string.
Any suggestions for how to fix this? The application is that I want to
start launcher program A, which in turn loads program B. Program B may
be a Test::Unit test suite, and Test::Unit gets the test suite name from
$0. So I either end up with the test suite having the name of program A
(which is wrong), or a truncated version of program B's name (which is
also wrong)
Thanks,
Brian.