onaliapoor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2013-Feb-25 18:47 UTC
Ruby pack - TypeError: can''t convert String into Integer
I am getting TypeError: can''t convert String into Integer, I found duplicate answer too, but I am facing this error for ''pack''. Other confusion is, it is working fine with ruby 1.8.7, not with ruby 1.9.3, here is the code irb(main):003:0> length=nil => nil irb(main):004:0> token_string ||= ["A".."Z","a".."z","0".."9"].collect { |r| r.to_a }.join + %q(!$:*) => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$:*" irb(main):005:0> token = (0..(length ? length : 60)).collect { token_string[rand( token_string.size)]}.pack("c*") TypeError: can''t convert String into Integer from (irb):5:in `pack'' from (irb):5 from /home/appandya/.rvm/rubies/ruby-1.9.3-p374/bin/irb:13:in `<main>'' irb(main):006:0> Ant Ideas? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/pBzoq-jMD60J. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2013-Feb-25 21:24 UTC
Re: Ruby pack - TypeError: can''t convert String into Integer
On Monday, February 25, 2013 6:47:20 PM UTC, onali...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Other confusion is, it is working fine with ruby 1.8.7, not with ruby > 1.9.3, here is the code > >irb(main):003:0> length=nil> => nil > irb(main):004:0> token_string ||= ["A".."Z","a".."z","0".."9"].collect { > |r| r.to_a }.join + %q(!$:*) > => "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$:*" > irb(main):005:0> token = (0..(length ? length : 60)).collect { > token_string[rand( token_string.size)]}.pack("c*") > TypeError: can''t convert String into Integer > from (irb):5:in `pack'' > from (irb):5 > from /home/appandya/.rvm/rubies/ruby-1.9.3-p374/bin/irb:13:in `<main>'' > irb(main):006:0> > > >I''ve no idea what you''re trying to do here, but the underlying cause is that on ruby 1.8.7: ''123''[0] #=> 49, the byte value of the first character but on ruby 1.9.3 ''123''[0] #=> ''1'', a string of length 1 beginning at the specified offset Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/_7vRy1qTL4UJ. For more options, visit https://groups.google.com/groups/opt_out.