Michael Glaesemann
7/10/2008 5:26:00 AM
On Jul 10, 2008, at 12:48 AM, Skave Rat 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 Glaesemann
grzm seespotcode net