[ruby-talk:00232] Re: occur.rb in ruby's sample directory
From:
gotoken@... (GOTO Kentaro)
Date:
1999-02-15 00:18:06 UTC
List:
ruby-talk #232
Hi
In message "[ruby-talk:00231] occur.rb in ruby's sample directory"
on 99/02/14, Mathowiz@aol.com <Mathowiz@aol.com> writes:
>I tried the following, but I can't believe that the sample script
>could be wrong, anyone want to explain to me what's going on?:
>
>C:\ruby\sample>ruby occur.rb occur.rb
>occur.rb:7: undefined method `+' for nil (NameError)
> from occur.rb:6:in `each'
> from occur.rb:6
>-------------------------------------------------------------------
>occur.rb is very short:
>--------------------------------------
># word occurrence listing
># usege: ruby occur.rb file..
>#freq = {}
>freq = Hash.new(0)
>while gets()
> for word in $_.split(/\W+/)
> freq[word] +=1
> end
>end
You maybe use ruby-1.2.x. In ruby-1.2.x, Hash elements
cannot be initialized by the argument of Hash.new.
This feature is available in ruby-1.3 or later.
The version of ruby can be obtained by a command line option `-v'
or a constant `VERSION'.
Hope this helps.
-- gotoken