# Strange error in jcode.rb when converting range to array

**URL:** <https://www.ruby-forum.com/t/strange-error-in-jcode-rb-when-converting-range-to-array/70282>\
**Category:** Ruby\
**Created:** [September 27, 2006, 11:44pm UTC](https://www.ruby-forum.com/t/strange-error-in-jcode-rb-when-converting-range-to-array/70282 "2006-09-27T23:44:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hammed\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Hammed\_M](https://www.ruby-forum.com/u/Hammed_M)\
**Post date:** [September 27, 2006, 11:44pm UTC](https://www.ruby-forum.com/t/strange-error-in-jcode-rb-when-converting-range-to-array/70282/1 "2006-09-27T23:44:16Z")

</div>

In my rails app I’ve line with the following code:

(“a”…“z”).to\_a

Simple enough and it’s been working for a while. Last night this line  
started throwing the following error:

undefined method `[]' for nil:NilClass /usr/local/lib/ruby/1.8/jcode.rb:83:in`succ!’  
/usr/local/lib/ruby/1.8/jcode.rb:94

I looked up jcode.rb and the comments for this file say that it’s “#  
jcode.rb - ruby code to handle japanese (EUC/SJIS) string”

This is the part of jcode.rb that throws the error (line 83)

78 def succ!  
79 reg = end\_regexp  
80 if self =~ reg  
81 succ\_table = SUCC[$KCODE[0,1].downcase]  
83 begin  
84 self[-1] += succ\_table[self[-1]]  
85 self[-2] += 1 if self[-1] == 0  
86 end while self !~ reg  
87 self  
88 else  
89 original\_succ!  
90 end  
91 end

Debugging is difficult because if I restart the app, the problem goes  
away…for a while. Has anyone else encountered this error before?

It’s obviously being caused by something I’ve added to my app  
recently. I just can’t figure out what.

ruby -v  
ruby 1.8.4 (2005-12-24) [i686-darwin8.5.2]

Thanks

Hammed

---

<div class="post-metadata">

**Author:** ![Hammed\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Hammed\_M](https://www.ruby-forum.com/u/Hammed_M)\
**Post date:** [September 28, 2006, 7:21pm UTC](https://www.ruby-forum.com/t/strange-error-in-jcode-rb-when-converting-range-to-array/70282/2 "2006-09-28T19:21:04Z")

</div>

Hammed M. wrote:

> In my rails app I’ve line with the following code:
> 
> (“a”…“z”).to\_a

When I try this with jcode loaded it immediately breaks. It looks like  
other people have noticed it too and there is a fix:

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/28980](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/28980)

I guess you will have to work around it for now.

---

<div class="post-metadata">

**Author:** ![Hammed\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Hammed\_M](https://www.ruby-forum.com/u/Hammed_M)\
**Post date:** [September 29, 2006, 2:16am UTC](https://www.ruby-forum.com/t/strange-error-in-jcode-rb-when-converting-range-to-array/70282/3 "2006-09-29T02:16:19Z")

</div>

Hi,

In message “Re: Strange error in jcode.rb when converting range to  
array”  
on Fri, 29 Sep 2006 02:20:18 +0900, “Manfred Stienstra”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|Hammed M. wrote:  
|\> In my rails app I’ve line with the following code:  
|\>  
|\> (“a”…“z”).to\_a  
|  
|When I try this with jcode loaded it immediately breaks. It looks like  
|other people have noticed it too and there is a fix:  
|  
|[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/28980](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/28980)

No, it’s about 1.9 and the OP was using 1.8.4. I will examine it  
later.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![Hammed\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Hammed\_M](https://www.ruby-forum.com/u/Hammed_M)\
**Post date:** [September 29, 2006, 5:28am UTC](https://www.ruby-forum.com/t/strange-error-in-jcode-rb-when-converting-range-to-array/70282/4 "2006-09-29T05:28:59Z")

</div>

Hi,

In message “Re: Strange error in jcode.rb when converting range to  
array”  
on Fri, 29 Sep 2006 09:49:03 +0900, “Hammed M.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|The perplexing part for me was why jcode.rb was even being used by my  
|code. A bit embarrasing to admit on a mailing list but somehow the  
|line include “jcode” got included in one of my less used rails  
|controller. I don’t have any need for Japanese characters in my app so  
|I can’t imagine adding that line myself. I’m suspecting Textmate has a  
|hotkey for inserting that line that I pressed inadvertantly.

I’ve heard Rails uses jcode to handle UTF-8.

I was telling the article in the ruby-dev list has nothing related to  
your problem. It is caused by a bug in jcode.rb, and is just fixed in  
the CVS.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![Hammed\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Hammed\_M](https://www.ruby-forum.com/u/Hammed_M)\
**Post date:** [September 29, 2006, 2:50am UTC](https://www.ruby-forum.com/t/strange-error-in-jcode-rb-when-converting-range-to-array/70282/5 "2006-09-29T02:50:21Z")

</div>

Hi Matz,

The perplexing part for me was why jcode.rb was even being used by my  
code. A bit embarrasing to admit on a mailing list but somehow the  
line include “jcode” got included in one of my less used rails  
controller. I don’t have any need for Japanese characters in my app so  
I can’t imagine adding that line myself. I’m suspecting Textmate has a  
hotkey for inserting that line that I pressed inadvertantly.

Hammed
