Created
October 26, 2013 07:57
-
-
Save joaquimadraz/7166555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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