I'm writing a simple function in a ruby script to get the ID attribute from some JSON data.
def getObjectTypeId()
objects = post(@server.oS.getAllTypeObjectCounts())
myObject = objects.find_all{|xObjectCountInfo| xObjectCountInfo['ObjectInfo']['ObjectTypeID'] == 'myObjectTypeID'}
puts myObject
@objectTypeId = myObject['ObjectInfo']['ID']
end
The error is happening on the final line of the function. As you can see, I'm printing myObject to the console to verify that it's a hash and not an array (which is the most common issue I've seen that causes this error). Here's a snippet of the output:
{"_class"=>"XObjectCountInfo", "ObjectInfo"=>{"_class"=>"XObjectInfo", "ID"=>"10102", "ObjectTypeID"=>"myObjectTypeID"}}
What could be causing me to get the "can't convert String to Integer" type error?
snake_caseinstead ofcamelCasewhen naming functions an variables in Ruby. This is the standard.