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)
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
endfoobar ({: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
=> nilfoobar ({:id => “MyID”})
(irb):2: warning: Object#id will be deprecated; use Object#object_id
1780410
=> nildef foobad(args)
puts args[:id]
end
=> nilfoobad({:id => “MyID”})
MyID
=> nil
Michael G.
grzm seespotcode net
thanks, I knew I missed womething.
Works fine now
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs