Why is my array a hash?

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 :frowning:


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 :slight_smile:

Lady Michelle B. [email protected] 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.

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

Lady Michelle B. [email protected] 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… :slight_smile:

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/, you’ll have just that!

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

HTH!
Tim H.

Wybo D. [email protected] wrote:

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.

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?

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

Wybo D. [email protected] 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.

HTH,
Tim H.

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.

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