# Ruby error

**URL:** <https://www.ruby-forum.com/t/ruby-error/195596>\
**Category:** Ruby\
**Created:** [September 26, 2010, 7:13am UTC](https://www.ruby-forum.com/t/ruby-error/195596 "2010-09-26T07:13:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![woow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@woow](https://www.ruby-forum.com/u/woow)\
**Post date:** [September 26, 2010, 7:13am UTC](https://www.ruby-forum.com/t/ruby-error/195596/1 "2010-09-26T07:13:42Z")

</div>

Please help me to figure why ruby is throwing following error…

## following is my code.

#!/usr/bin/ruby  
require ‘procStartupTimes’  
require ‘rubygems’  
require ‘gruff’

g = Gruff::Line.new  
g.title = “My Graph”

a = [1, 2, 3, 4, 4, 3,2, 3, 1, 5]

g.data(“Apples”, a)

puts a.size

inc = 2

x = Hash.new(a.size/inc)  
x[0] = a.first.to\_s  
x[a.size/inc] = a.last.to\_s

for i in 1…((a.size/inc)-1) do  
x[inc_i] = a[inc_i].to\_s  
end

puts x.inspect

g.labels = x  
g.write(‘my\_fruity\_graph.png’)

* * *

it throws below error…could someone pls tell me what causes this?

10  
{5=\>“5”, 0=\>“1”, 6=\>“2”, 2=\>“3”, 8=\>“1”, 4=\>“4”}  
/usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/base.rb:1115:in  
`annotate': can't convert Fixnum into String (TypeError) from /usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/base.rb:1115:in`annotate\_scaled’  
from ./gruff\_fix.rb:12:in `draw_label' from /usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/line.rb:80:in`draw’  
from  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`each_with_index' from /usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/line.rb:76:in`each’  
from  
/usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/line.rb:76:in  
`each_with_index' from /usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/line.rb:76:in`draw’  
from  
/usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/line.rb:71:in `each' from /usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/line.rb:71:in`draw’  
from  
/usr/lib/ruby/gems/1.8/gems/gruff-0.3.6/lib/gruff/base.rb:487:in `write’  
from ./test3.rb:28

---

<div class="post-metadata">

**Author:** ![woow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@woow](https://www.ruby-forum.com/u/woow)\
**Post date:** [September 26, 2010, 8:45am UTC](https://www.ruby-forum.com/t/ruby-error/195596/2 "2010-09-26T08:45:11Z")

</div>

Ruwan B. wrote:

> Please help me to figure why ruby is throwing following error…

I know nothing about Gruff, but I do notice this:

> x = Hash.new(a.size/inc)

That probably doesn’t do what you think. It says “create a Hash which  
returns 5 for any non-existent element” (try puts x[1000] for example)

Hashes don’t have sizes. If you really want a Hash then it should be

x = Hash.new

or just

x = {}

---

<div class="post-metadata">

**Author:** ![woow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@woow](https://www.ruby-forum.com/u/woow)\
**Post date:** [September 26, 2010, 3:56pm UTC](https://www.ruby-forum.com/t/ruby-error/195596/3 "2010-09-26T15:56:15Z")

</div>

Brian C. wrote:

> Ruwan B. wrote:
> 
> > Please help me to figure why ruby is throwing following error…
> 
> I know nothing about Gruff, but I do notice this:
> 
> > x = Hash.new(a.size/inc)
> 
> That probably doesn’t do what you think. It says “create a Hash which  
> returns 5 for any non-existent element” (try puts x[1000] for example)
> 
> Hashes don’t have sizes. If you really want a Hash then it should be
> 
> x = Hash.new
> 
> or just
> 
> x = {}

worked like a charm…thanx so much…
