You should be able to implement userType
as an instance method.
class MyResource < ActiveResource::Base
self.site = "http://api.example.com/"
def userType
UserType.new(userTypeId: super.userTypeId, description: super.description)
end
end
This works because ActiveResource automatically creates a "getter" method for each of the keys in the attributes hash that you pass into the class constructor. When the called attribute method corresponds to a hash value, ActiveResource returns an instance of an automatically generated class MyResource::UserType
, which respectively will respond to the userTypeId
and the description
methods. You can get hold of this instance by calling super
within the overridden method, and passing the value of userTypeId
and description
to your own class.
Edit: - Corrected class name
PS: Have a look at the ActiveResource#load method for more details on how attribute getter methods get generated.