Problem with hash in function

Somehow I’m missing something really basic. Why is following function
now working?

def foobar(args)
puts args.id
end

foobar ({:id => “MyID”})
#=> some random number (e.g. -616990888)

args.id will return your object_id. I am not sure that’s what you
want. You want:

puts args[:id]

Jayanth

On Jul 10, 2008, at 12:48 AM, Skave R. wrote:

Somehow I’m missing something really basic. Why is following function
now working?

def foobar(args)
puts args.id
end

foobar ({:id => “MyID”})
#=> some random number (e.g. -616990888)

Are you expecting foobar({:id => “MyID”}) to return “MyID”? args.id
will return the object id of args (though this is deprecated. I
suspect you want args[:id] instead.

def foobar(args)
puts args.id
end
=> nil

foobar ({:id => “MyID”})
(irb):2: warning: Object#id will be deprecated; use Object#object_id
1780410
=> nil

def foobad(args)
puts args[:id]
end
=> nil

foobad({:id => “MyID”})
MyID
=> nil

Michael G.
grzm seespotcode net

thanks, I knew I missed womething.

Works fine now