Class: Mingle::MingleNumber

Inherits:
MingleValue
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/mingle.rb

Direct Known Subclasses

MingleFloatingPointImpl, MingleIntegerImpl

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num, convert_meth = nil) ⇒ MingleNumber

Returns a new instance of MingleNumber.



140
141
142
143
144
# File 'lib/mingle.rb', line 140

def initialize( num, convert_meth = nil )
    
    not_nil( num, :num )
    @num = convert_meth ? num.send( convert_meth ) : num
end

Instance Attribute Details

#numObject (readonly)

Returns the value of attribute num.



138
139
140
# File 'lib/mingle.rb', line 138

def num
  @num
end

Instance Method Details

#<=>(other) ⇒ Object



165
166
167
168
169
170
171
172
# File 'lib/mingle.rb', line 165

def <=>( other )
    
    if other.is_a?( MingleNumber )
        @num <=> other.num
    else
        raise TypeError, other.class.to_s
    end
end

#==(other) ⇒ Object Also known as: eql?



157
158
159
# File 'lib/mingle.rb', line 157

def ==( other )
    other.class == self.class && other.num == @num
end

#inspectObject



152
153
154
# File 'lib/mingle.rb', line 152

def inspect
    to_s.inspect
end

#to_fObject



180
181
182
# File 'lib/mingle.rb', line 180

def to_f
    @num.to_f
end

#to_iObject



175
176
177
# File 'lib/mingle.rb', line 175

def to_i
    @num.to_i
end

#to_sObject



147
148
149
# File 'lib/mingle.rb', line 147

def to_s
    @num.to_s
end