Hash : TypeError: can't convert Symbol into Integer

U

Une Bévue

here is my code :

h = Hash.new (same error with h = {} )
h[:path] = "/Users/yt/lib/ruby-i386/"
puts "# -> h[:path] = #{h[:path]}"
info_for(h[:path]).each {|k,v| puts "# -> #{k} (#{k.class}) => #{v}
(#{v.class})"}


with :
def info_for(h)
raise ArgumentError, "The file '#{h[:path]}' does not exist!" unless
File.exist?(h[:path])
a = MacTypes::Alias.path(h[:path])
ho = OSAX::ScriptingAddition.new('StandardAdditions',
StandardAdditions).info_for(a.desc)
h = h.merge(ho)
h = original_item(h) if h[:alias]
return h
end

the line which raises this TypeError: can't convert Symbol into Integer
is the first of info_for(h) that's to say :
raise ArgumentError, "The file '#{h[:path]}' does not exist!" unless
File.exist?(h[:path])

clearly i'm in the dark ))
 
R

Rick DeNatale

2010/5/28 Une B=E9vue said:
here is my code :

h =3D Hash.new =A0(same error with h =3D {} )
h[:path] =3D "/Users/yt/lib/ruby-i386/"
puts "# -> h[:path] =3D #{h[:path]}"
info_for(h[:path]).each {|k,v| puts "# -> #{k} (#{k.class}) =3D> #{v}
(#{v.class})"}

You are calling info_for with h[:path] which is"/Users/yt/lib/ruby-i386/"
def info_for(h)
=A0raise ArgumentError, "The file '#{h[:path]}' does not exist!" unless
File.exist?(h[:path])



the line which raises this TypeError: can't convert Symbol into Integer
is the first of info_for(h) that's to say :
raise ArgumentError, "The file '#{h[:path]}' does not exist!" unless
File.exist?(h[:path])

This then tries to evaluate:

"/Users/yt/lib/ruby-i386/"[:path]
clearly i'm in the dark ))


J'esp=E8re qu'il est peu un plus lumineux maintenant.


--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 
U

Une Bévue

Une Bévue said:
if i change the starting point to :

h = {:path => "/Users/yt/lib/ruby-i386/"}

same error at same line )))

I've found MY error, it isn't in info_for(h) but rather in the calling :
truc = info_for(h[:path])

better using :
truc = info_for(h)
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top