# Why is my array a hash?

**URL:** <https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361>\
**Category:** Ruby\
**Created:** [November 19, 2005, 12:08pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361 "2005-11-19T12:08:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 19, 2005, 12:08pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/1 "2005-11-19T12:08:28Z")

</div>

I have a chunk of code, where I define an array, and the very next time  
I use it, Ruby thinks that it’s a hash instead ☹

…  
step = Array.new  
astep, line = getNextWord(line)  
while astep != nil  
{  
step.push(astep) \<- gets error ‘odd number list for hash’  
astep, line = getNextWord(line)  
}  
…

What’s with this?

Michelle 🙂

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 19, 2005, 12:20pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/2 "2005-11-19T12:20:33Z")

</div>

Lady Michelle B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> }  
> …
> 
> What’s with this?

Ruby doesn’t think step is a hash.

The proper syntax for a while loop in ruby is:

```
while CONDITION
  ...
end

```

Ruby is seeing your { } and interpreting them as a hash  
definition, not a block as in other languages.

```
while astep != nil
  step.push(astep)
  astep, line = getNextWord(line)
end

```

HTH,  
Tim H.

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 19, 2005, 12:26pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/3 "2005-11-19T12:26:35Z")

</div>

Thanks, now if I could only teach Vim to match do,end pairs the way  
it’ll match braces

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 19, 2005, 1:08pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/4 "2005-11-19T13:08:53Z")

</div>

Lady Michelle B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks, now if I could only teach Vim to match do,end pairs  
> the way it’ll match braces

Funny you should mention that… 🙂

If you drop the $VIMRUNTIME/macros/matchit.vim file in your  
~/.vim/plugins/, enable filetype plugins support in your vimrc,  
and install the latest vim-ruby package from  
[http://vim-ruby.rubyforge.org/](http://vim-ruby.rubyforge.org/), you’ll have just that!

Detailed instructions on this can be found at the bottom of this  
page: [http://tinyurl.com/avfzf](http://tinyurl.com/avfzf) [[rubyforge.org](http://rubyforge.org) cvs].

HTH!  
Tim H.

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 19, 2005, 9:28pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/5 "2005-11-19T21:28:55Z")

</div>

Wybo D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > [http://vim-ruby.rubyforge.org/](http://vim-ruby.rubyforge.org/), you’ll have just that!
> > 
> > > " keywords. Try “:echo b:match\_words” to be sure.  
> > > filetype indent on " Enable filetype-specific indenting  
> > > filetype plugin on " Enable filetype-specific plugins

It looks like either matchit.vim is not being loaded (is it in  
your ~/.vim/plugin/ directory?) or ftplugin/ruby.vim isn’t  
being loaded.

I guess I had a typo above where I said ~/.vim/plugins/ … that  
should have been ~/.vim/plugin/ . The instructions at the  
bottom of the CVS link above are correct tho.

HTH,  
Tim H.

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 19, 2005, 11:59pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/6 "2005-11-19T23:59:24Z")

</div>

On Sun, 20 Nov 2005, Tim H. wrote:

> It looks like either matchit.vim is not being loaded (is it in  
> your ~/.vim/plugin/ directory?) or ftplugin/ruby.vim isn’t  
> being loaded.

It _is_ loaded - I tested that by introducing an error (iif instead of  
if)  
in the matchit.vim file, and that was detected:

Error detected while processing /home/wybo/.vim/plugin/matchit.vim:  
line 40:  
E492: Not an editor command: iif exists(“loaded\_matchit”) || &cp  
Hit ENTER or type command to continue

In my ~/.vim I have:

./doc:  
total 24  
-rw-r–r-- 1 wybo users 18998 20040512 16:28:33 matchit.txt  
-rw-r–r-- 1 wybo users 1961 20051119 13:29:28 tags

./plugin:  
total 32  
-rw-r–r-- 1 wybo users 30374 20040515 17:10:28 matchit.vim

./syntax:  
total 8  
-rw-r–r-- 1 wybo users 1119 20050705 06:58:57 eruby.vim  
-rw-r–r-- 1 wybo users 4081 20051119 13:26:41 ruby.vim

Is that correct?

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 19, 2005, 1:51pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/7 "2005-11-19T13:51:11Z")

</div>

On Sat, 19 Nov 2005, Tim H. wrote:

> Detailed instructions on this can be found at the bottom of this  
> page: [http://tinyurl.com/avfzf](http://tinyurl.com/avfzf) [[rubyforge.org](http://rubyforge.org) cvs].

This says:

> > Now you can do “:help matchit”, and you should be able to use “%” on Ruby

the :help works, but the % does not

> > " keywords. Try “:echo b:match\_words” to be sure.

this says:

E121: Undefined variable: b:match\_words  
E15: Invalid expression: b:match\_words

what’s wrong? My vim is version 6.3.23 and my .vimrc has:

set nocompatible " We’re running Vim, not Vi!  
filetype on " Enable filetype detection  
filetype indent on " Enable filetype-specific indenting  
filetype plugin on " Enable filetype-specific plugins

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 20, 2005, 10:06am UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/8 "2005-11-20T10:06:41Z")

</div>

Wybo D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> E492: Not an editor command: iif exists(“loaded\_matchit”) || &cp  
> total 32  
> -rw-r–r-- 1 wybo users 30374 20040515 17:10:28 matchit.vim
> 
> /syntax:  
> total 8  
> -rw-r–r-- 1 wybo users 1119 20050705 06:58:57 eruby.vim  
> -rw-r–r-- 1 wybo users 4081 20051119 13:26:41 ruby.vim
> 
> Is that correct?

Yup. However, Item 6 in ftplugin/ruby.vim maybe be misleading.  
matchit.vim doesn’t set the b:match\_words variable. This is  
done by the language-specific ftplugins (the ones that support  
matchit, anyway). Thus, echo’ing the b:match\_world var will  
only work from inside the buffer of a ruby file.

Apologies if this is a stupid question, but… with the setup  
you describe above, and with the active buffer being a correctly  
identified ruby file, does the `:echo b:match_words` test work?

If you still have trouble, try asking on the vim-ruby-devel ML,  
found at [http://rubyforge.org/mail/?group\_id=16](http://rubyforge.org/mail/?group_id=16).

HTH,  
Tim H.

---

<div class="post-metadata">

**Author:** ![michelle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@michelle](https://www.ruby-forum.com/u/michelle)\
**Post date:** [November 20, 2005, 4:12pm UTC](https://www.ruby-forum.com/t/why-is-my-array-a-hash/48361/9 "2005-11-20T16:12:15Z")

</div>

On Sun, 20 Nov 2005, Tim H. wrote:

> Apologies if this is a stupid question, but… with the setup  
> you describe above, and with the active buffer being a correctly  
> identified ruby file, does the `:echo b:match_words` test work?

no, it doesn’t; :se syntax says syntax=ruby and :echo b:match\_words  
says

E121: Undefined variable: b:match\_words  
E15: Invalid expression: b:match\_words

> If you still have trouble, try asking on the vim-ruby-devel ML,  
> found at [http://rubyforge.org/mail/?group\_id=16](http://rubyforge.org/mail/?group_id=16).

I’ll do that, this is getting away from ruby too much… thanks sofar
