Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Frozen string problem, but I haven't frozen anything? (http://www.velocityreviews.com/forums/t813640-frozen-string-problem-but-i-havent-frozen-anything.html)

LC Geldenhuys 02-17-2004 08:45 AM

Frozen string problem, but I haven't frozen anything?
 
Hi,

I am new to Ruby. I'm trying to get some Ruby scripts going to manage
or CVS log message emails. (I haven't written them myself, got them
from the web.)

I get:
/home/cvs/repository/CVSROOT/commitinfo.rb:26:in `tr_s!': can't modify
frozen string (TypeError)
from /home/cvs/repository/CVSROOT/commitinfo.rb:26

I've done some reading, and I suspect I understand what the frozen
string issue is about. The problem is, I don't see how/why this string
is frozen? Here is the relevant code snippet:

-----------------------------------
if ARGV.size < 4
puts "Usage: #{$0} CVSROOT USER modulepath file1 [file2...]"
exit 1 # No way!
end

$cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV

$cvsroot.tr_s!('/', '/')
$modulepath.tr_s!('/', '/')
-----------------------------------

The two lines using 'tr_s!' causes the problem, but I don't see
how/why $cvsroot or $modulepath is 'frozen'? Might it be due to the
fact that they are passed to the script, i.e. some global/local scope
issue?

Regards,
Lourens


Emmanuel Touzery 02-17-2004 09:04 AM

Re: Frozen string problem, but I haven't frozen anything?
 
LC Geldenhuys wrote:

>Hi,
>
>I am new to Ruby. I'm trying to get some Ruby scripts going to manage
>or CVS log message emails. (I haven't written them myself, got them
>from the web.)
>
>I get:
>/home/cvs/repository/CVSROOT/commitinfo.rb:26:in `tr_s!': can't modify
>frozen string (TypeError)
> from /home/cvs/repository/CVSROOT/commitinfo.rb:26
>
>I've done some reading, and I suspect I understand what the frozen
>string issue is about. The problem is, I don't see how/why this string
>is frozen? Here is the relevant code snippet:
>
>-----------------------------------
>if ARGV.size < 4
> puts "Usage: #{$0} CVSROOT USER modulepath file1 [file2...]"
> exit 1 # No way!
>end
>
>$cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV
>
>$cvsroot.tr_s!('/', '/')
>$modulepath.tr_s!('/', '/')
>-----------------------------------
>
>The two lines using 'tr_s!' causes the problem, but I don't see
>how/why $cvsroot or $modulepath is 'frozen'? Might it be due to the
>fact that they are passed to the script, i.e. some global/local scope
>issue?
>
>

you can't modify values in ARGV. you have to copy the values.




LC Geldenhuys 02-17-2004 01:36 PM

Re: Frozen string problem, but I haven't frozen anything?
 
On Tue, 17 Feb 2004 18:04:00 +0900, Emmanuel Touzery
<emmanuel.touzery@wanadoo.fr> wrote:

>LC Geldenhuys wrote:
>
>>Hi,
>>
>>I am new to Ruby. I'm trying to get some Ruby scripts going to manage
>>or CVS log message emails. (I haven't written them myself, got them
>>from the web.)
>>
>>I get:
>>/home/cvs/repository/CVSROOT/commitinfo.rb:26:in `tr_s!': can't modify
>>frozen string (TypeError)
>> from /home/cvs/repository/CVSROOT/commitinfo.rb:26
>>
>>I've done some reading, and I suspect I understand what the frozen
>>string issue is about. The problem is, I don't see how/why this string
>>is frozen? Here is the relevant code snippet:
>>
>>-----------------------------------
>>if ARGV.size < 4
>> puts "Usage: #{$0} CVSROOT USER modulepath file1 [file2...]"
>> exit 1 # No way!
>>end
>>
>>$cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV
>>
>>$cvsroot.tr_s!('/', '/')
>>$modulepath.tr_s!('/', '/')
>>-----------------------------------
>>
>>The two lines using 'tr_s!' causes the problem, but I don't see
>>how/why $cvsroot or $modulepath is 'frozen'? Might it be due to the
>>fact that they are passed to the script, i.e. some global/local scope
>>issue?
>>
>>

>you can't modify values in ARGV. you have to copy the values.
>
>


Thanks, the following now seems to work.

$cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV

$cvsroot = $cvsroot_in.dup
$modulepath = $modulepath_in.dup

$cvsroot.tr_s!('/', '/')
$modulepath.tr_s!('/', '/')

Cheers,
Lourens


Robert Klemme 02-17-2004 02:12 PM

Re: Frozen string problem, but I haven't frozen anything?
 

"LC Geldenhuys" <lcgeldenhuys@hotmail.com> schrieb im Newsbeitrag
news:s26430l9o2e34veibgqpc76kvvnn67ras1@4ax.com...
> On Tue, 17 Feb 2004 18:04:00 +0900, Emmanuel Touzery
> <emmanuel.touzery@wanadoo.fr> wrote:
>
> >LC Geldenhuys wrote:
> >
> >>Hi,
> >>
> >>I am new to Ruby. I'm trying to get some Ruby scripts going to manage
> >>or CVS log message emails. (I haven't written them myself, got them
> >>from the web.)
> >>
> >>I get:
> >>/home/cvs/repository/CVSROOT/commitinfo.rb:26:in `tr_s!': can't modify
> >>frozen string (TypeError)
> >> from /home/cvs/repository/CVSROOT/commitinfo.rb:26
> >>
> >>I've done some reading, and I suspect I understand what the frozen
> >>string issue is about. The problem is, I don't see how/why this string
> >>is frozen? Here is the relevant code snippet:
> >>
> >>-----------------------------------
> >>if ARGV.size < 4
> >> puts "Usage: #{$0} CVSROOT USER modulepath file1 [file2...]"
> >> exit 1 # No way!
> >>end
> >>
> >>$cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV
> >>
> >>$cvsroot.tr_s!('/', '/')
> >>$modulepath.tr_s!('/', '/')
> >>-----------------------------------
> >>
> >>The two lines using 'tr_s!' causes the problem, but I don't see
> >>how/why $cvsroot or $modulepath is 'frozen'? Might it be due to the
> >>fact that they are passed to the script, i.e. some global/local scope
> >>issue?
> >>
> >>

> >you can't modify values in ARGV. you have to copy the values.
> >
> >

>
> Thanks, the following now seems to work.
>
> $cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV
>
> $cvsroot = $cvsroot_in.dup
> $modulepath = $modulepath_in.dup
>
> $cvsroot.tr_s!('/', '/')
> $modulepath.tr_s!('/', '/')


Why don't you just do

$cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV

$cvsroot.tr_s('/', '/')
$modulepath.tr_s('/', '/')

? And, why do you use global variables at all?

Regards

robert


Mark Hubbart 02-17-2004 07:48 PM

Re: Frozen string problem, but I haven't frozen anything?
 

On Feb 17, 2004, at 6:14 AM, Robert Klemme wrote:

> Why don't you just do
>
> $cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV
>
> $cvsroot.tr_s('/', '/')
> $modulepath.tr_s('/', '/')


You probably meant:
$cvsroot = $cvsroot_in.tr_s('/', '/')
$modulepath = $modulepath_in.tr_s('/', '/')

but how about:
$cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV.map{|a|a.dup}

this unfreezes everything automagically.

Cheers,
Mark




Robert Klemme 02-18-2004 08:13 AM

Re: Frozen string problem, but I haven't frozen anything?
 

"Mark Hubbart" <discord@mac.com> schrieb im Newsbeitrag
news:3AA77270-6182-11D8-B680-000502FDD5CC@mac.com...
>
> On Feb 17, 2004, at 6:14 AM, Robert Klemme wrote:
>
> > Why don't you just do
> >
> > $cvsroot_in, $cvsuser, $modulepath_in, *$cvsfiles = *ARGV
> >
> > $cvsroot.tr_s('/', '/')
> > $modulepath.tr_s('/', '/')

>
> You probably meant:
> $cvsroot = $cvsroot_in.tr_s('/', '/')
> $modulepath = $modulepath_in.tr_s('/', '/')


Yes. Thanks for correcting that.

> but how about:
> $cvsroot, $cvsuser, $modulepath, *$cvsfiles = *ARGV.map{|a|a.dup}
>
> this unfreezes everything automagically.


As always there are tons of ways to do things with Ruby. Which is good.
:-)

Regards

robert



All times are GMT. The time now is 04:52 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.