Hash : TypeError: can't convert Symbol into Integer

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

Une Bévue [email protected] wrote:

here is my code :

if i change the starting point to :

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

same error at same line )))

2010/5/28 Une Bévue [email protected]:

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})”}

You are calling info_for with h[:path] which
is"/Users/yt/lib/ruby-i386/"

def info_for(h)
raise 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ère qu’il est peu un plus lumineux maintenant.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: rubyredrick (Rick DeNatale) · GitHub
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Rick DeNatale [email protected] wrote:

J’espère qu’il est peu un plus lumineux maintenant.

Merci, j’avais vu ma connerie entre-temps )))

Une Bévue [email protected] wrote:

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)