В Python можно изменить фактический класс непосредственно:
class Domain(object):
def __init__(self, domain):
self.domain = domain
if ...:
self.__class__ = RegistrarA
else:
self.__class__ = RegistrarB
И затем следующее будет работать.
com = Domain('test.com') #load RegistrarA
com.lookup()
я использую этот подход успешно.
<%= link_to 'Destroy', post_comment_path(@post, comment),
data: {:confirm => 'Are you sure?'}, :method => :delete %>
в комментариях контроллер:
def destroy
@post = Post.find(params[:post_id])
@comment = Comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.html { redirect_to post_comments_path(@post) }
format.xml { head :ok }
end
end