我有这样的东西
class Reply < AR::Base
end
class VideoReply < Reply
def hello
p 'not ok'
end
end
class PostReply < Reply
def hello
p 'ok'
end
end
...
所以当我创建对象时:
# params[:reply][:type] = "VideoReply"
@reply = Reply.new(params[:reply])
如何调用子方法(在这种情况下VideoReply::hello
)?
UPD: 我只能想象非常愚蠢的解决方案:
@reply = Reply.new(params[:reply])
eval(@reply.type).find(@reply.id).hello
但这并不酷,我认为:)