Class: Types::RplComplex
- Inherits:
-
Object
- Object
- Types::RplComplex
- Defined in:
- lib/rpl/types/complex.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(value) ⇒ RplComplex
constructor
A new instance of RplComplex.
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ RplComplex
Returns a new instance of RplComplex.
9 10 11 12 13 14 15 16 |
# File 'lib/rpl/types/complex.rb', line 9 def initialize( value ) raise RplTypeError unless self.class.can_parse?( value ) # we systematicalyl trim enclosing () value = value[1..-2] if value.is_a?( String ) && value[0] == '(' && value[-1] == ')' @value = Complex( value ) end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/rpl/types/complex.rb', line 7 def value @value end |
Class Method Details
.can_parse?(value) ⇒ Boolean
22 23 24 25 26 27 |
# File 'lib/rpl/types/complex.rb', line 22 def self.can_parse?( value ) # we systematically trim enclosing () value = value[1..-2] if value.is_a?( String ) && value[0] == '(' && value[-1] == ')' !Complex( value, exception: false ).nil? end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 32 |
# File 'lib/rpl/types/complex.rb', line 29 def ==( other ) other.class == RplComplex && other.value == value end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/rpl/types/complex.rb', line 18 def to_s "(#{@value})" end |