Skip to content

Instantly share code, notes, and snippets.

@knzai
Created October 30, 2009 20:49
Show Gist options
  • Save knzai/222710 to your computer and use it in GitHub Desktop.
Save knzai/222710 to your computer and use it in GitHub Desktop.
An example of differing ways of abstracting initialization into the parent
class AbstractScraper
def initialize(username, password)
@agent = WWW::Mechanize.new
@agent.user_agent_alias = "Windows Mozilla"
@agent.keep_alive = false
login(username, password)
end
end
class NormalAScraper < AbstractScraper
end
class NormalBScraper < AbstractScraper
end
class GoofyScraper < AbstractScraper
def initialize
@agent = WWW::Mechanize.new
@agent.user_agent_alias = "Windows Mozilla"
@agent.keep_alive = false
login
end
end
class AbstractScraper
def initialize(username, password)
initialize_agent
login(username, password)
end
def initialize_agent
@agent = WWW::Mechanize.new
@agent.user_agent_alias = "Windows Mozilla"
@agent.keep_alive = false
end
end
class NormalAScraper < AbstractScraper
end
class NormalBScraper < AbstractScraper
end
class GoofyScraper < AbstractScraper
def initialize
initialize_agent
login
end
end
class AbstractScraper
def initialize_agent
@agent = WWW::Mechanize.new
@agent.user_agent_alias = "Windows Mozilla"
@agent.keep_alive = false
end
end
class NormalAScraper < AbstractScraper
def initialize(username, password)
initialize_agent
login(username, password)
end
end
class NormalBScraper < AbstractScraper
def initialize(username, password)
initialize_agent
login(username, password)
end
end
class GoofyScraper < AbstractScraper
def initialize
initialize_agent
login
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment