Professional Web Applications Themes

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

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 ...

  1. #1

    Default 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

    LC Guest

  2. #2

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

    LC Geldenhuys wrote:
     
    you can't modify values in ARGV. you have to copy the values.



    Emmanuel Guest

  3. #3

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

    On Tue, 17 Feb 2004 18:04:00 +0900, Emmanuel Touzery
    <fr> wrote:
     
    >you can't modify values in ARGV. you have to copy the values.
    >
    >[/ref]

    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

    LC Guest

  4. #4

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


    "LC Geldenhuys" <com> schrieb im Newsbeitrag
    news:com... 
    > >you can't modify values in ARGV. you have to copy the values.
    > >
    > >[/ref]
    >
    > 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!('/', '/')[/ref]

    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

    Robert Guest

  5. #5

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


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

    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



    Mark Guest

  6. #6

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


    "Mark Hubbart" <com> schrieb im Newsbeitrag
    news:com... 
    >
    > You probably meant:
    > $cvsroot = $cvsroot_in.tr_s('/', '/')
    > $modulepath = $modulepath_in.tr_s('/', '/')[/ref]

    Yes. Thanks for correcting that.
     

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

    Regards

    robert

    Robert Guest

Similar Threads

  1. Problem with Authen::Captcha has frozen my development
    By Daniel Kaplan in forum PERL Modules
    Replies: 1
    Last Post: December 10th, 11:11 PM
  2. 1.8,frozen, and untaint
    By Ara.T.Howard in forum Ruby
    Replies: 1
    Last Post: September 25th, 05:10 PM
  3. Frozen Tools
    By Beth Haney in forum Adobe Photoshop Elements
    Replies: 2
    Last Post: July 10th, 02:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139