Skip to content

Instantly share code, notes, and snippets.

@joaquimadraz
Created October 26, 2013 07:57
Show Gist options
  • Save joaquimadraz/7166555 to your computer and use it in GitHub Desktop.
Save joaquimadraz/7166555 to your computer and use it in GitHub Desktop.
class Team
attr_accessor :name, :country
private_class_method :new
end
class Barcelona < Team
def initialize(name, country)
@name = name
@country = country
end
def self.constructor(name, country)
obj = allocate
obj.send(:initialize, name, country)
obj
end
end
require 'test/unit'
class TestBarcelonaTeam < Test::Unit::TestCase
def test_initialize_team
team = Barcelona.constructor("Barcelona", "Spain")
assert_equal "Barcelona", team.name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment