Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
$0 is truncated
Brian Candler
5/16/2009 1:04:00 PM
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.
--
Posted via
http://www.ruby-...
.
2 Answers
Robert Klemme
5/16/2009 1:45:00 PM
0
On 16.05.2009 15:03, Brian Candler wrote:
> 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)
Modifying $0 seems a bit hackish to me. Can't you just set the name
explicitly?
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...
Eric Hodel
5/16/2009 4:53:00 PM
0
On May 16, 2009, at 6:03, Brian Candler <b.candler@pobox.com> wrote:
> If I assign a new value to $0, I find it is truncated.
This behavior is OS dependent, try a different OS.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
$0 is truncated
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password