Exemple #1
0
    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)
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 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)
Exemple #6
0
 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)
Exemple #7
0
 def __new__(cls, *args, **kwargs):
     """Instantiate Vector.
     """
     return BuiltInClass.get_instance(cls, 'VECTOR', *args)
Exemple #8
0
 def __new__(cls, *args, **kwargs):
     """Instantiate Array.
     """
     return BuiltInClass.get_instance(cls, 'ARRAY', *args)
Exemple #9
0
 def __new__(cls, *args, **kwargs):
     """Instantiate String.
     """
     return BuiltInClass.get_instance(cls, 'String', *args)
Exemple #10
0
 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)