Skip to content

Instantly share code, notes, and snippets.

@darrencauthon
Created August 25, 2014 21:48
Show Gist options
  • Select an option

  • Save darrencauthon/81ebc24ffde69d298c09 to your computer and use it in GitHub Desktop.

Select an option

Save darrencauthon/81ebc24ffde69d298c09 to your computer and use it in GitHub Desktop.
Overriding the constructor
class RecordFinder
def initialize username, password
@username = username
@password = password
end
end
RecordFinder.class_eval do
def initialize
@username = ENV['USERNAME']
@password = ENV['PASSWORD']
end
end
# now, in my code, I can type:
#
# RecordFinder.new
#
# and in my tests, I can stub it like:
#
# RecordFinder.stubs(:new).returns record_finder
# instead of...
# RecordFinder.stubs(:new).with(username, password).returns record_finder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment