def __new__(cls, ratio): """Calls to create a new instance of Ratio. Args: ratio: String Returns: An instance. """ if '/' not in ratio: # An argument is ['2']. return Integer(ratio[0]) else: # An argument is ['10/5']. numerator, denominator = (int(i) for i in ratio.split('/')) if numerator % denominator == 0: return Integer(numerator // denominator) else: return BuiltInClass.get_instance(cls, 'RATIO', ratio)
def __new__(cls, *args, **kwargs): """Instantiates Keyword. If an instance of Keyword is already existed in object_table, returns the instance. Otherwise, a new instance is made. """ return BuiltInClass.get_instance(cls, 'KEYWORD', *args)
def __new__(cls, *args, **kwargs): """Instantiates Number. If an instance of Number is already existed in object_table, returns the instance. Otherwise, a new instance is made. """ return BuiltInClass.get_instance(cls, 'NUMBER', True)
def __new__(cls, *args, **kwargs): """Instantiates DoubleFloat. If an instance of DoubleFloat is already existed in object_table, returns the instance. Otherwise, a new instance is made. """ return BuiltInClass.get_instance(cls, 'LONG-FLOAT', *args)
def __new__(cls, *args, **kwargs): """Instantiates Bignum. If an instance of Bignum is already existed in object_table, returns the instance. Otherwise, a new instance is made. """ return BuiltInClass.get_instance(cls, 'BIGNUM', *args)
def __new__(cls, *args, **kwargs): """Instantiates Rational. If an instance of Rational is already existed in object_table, returns the instance. Otherwise, a new instance is made. """ return BuiltInClass.get_instance(cls, 'RATIONAL', True)
def __new__(cls, *args, **kwargs): """Instantiate Vector. """ return BuiltInClass.get_instance(cls, 'VECTOR', *args)
def __new__(cls, *args, **kwargs): """Instantiate Array. """ return BuiltInClass.get_instance(cls, 'ARRAY', *args)
def __new__(cls, *args, **kwargs): """Instantiate String. """ return BuiltInClass.get_instance(cls, 'String', *args)
def __new__(cls, *args, **kwargs): """Instantiates Sequence. If an instance of Sequence is already existed in object_table, returns the instance. Otherwise, a new instance is made. """ return BuiltInClass.get_instance(cls, 'SEQUENCE', True)