我想将一些来自 facebook 的数据映射到我的 User 类中。我现在阅读了一些关于继承、扩展、包含等的文章。但也许我理解错了。这是 Ruby 中数据映射的正确方法吗?
class User
attr_accessible :name, :address
def map_facebook
FacebookUserMapper.new(facebook_object, self)
end
end
class FacebookUserMapper
def initialize(facebook_user, user)
@facebook_user = facebook_user
@user = user
mapit
end
def self.map_it()
username
address
return @user
end
def username
@user.username = @facebook_user.name
end
def address
@user.address = @facebook_user.address
end
end