Skip to content

Instantly share code, notes, and snippets.

@liwh
Created November 23, 2010 07:48
Show Gist options
  • Save liwh/711422 to your computer and use it in GitHub Desktop.
Save liwh/711422 to your computer and use it in GitHub Desktop.
定义抽象类,实现代码重构
# app/models/abstract_server.rb
class AbstractServer < ActiveRecord::Base
self.abstract_class = true
validates_presence_of :name, :address, :username, :password, :encoding
validates_length_of :name, :maximum => 20, :allow_blank => true
validates_length_of :address, :maximum => 20, :allow_blank => true
validates_length_of :username, :password, :maximum => 20, :allow_blank => true
validates_length_of :encoding, :maximum => 10, :allow_blank => true
end
# app/models/server.rb
class Server < AbstractServer
# some other method
end
# app/models/sourcer.rb
class Sourcer < AbstractServer
# some other method
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment