next up previous contents index
Next: II. Composite Reference Manual Up: I. FeResPost Reference Manual Previous: I.6 The ``Post'' module   Contents   Index


I.7 Arguments coercion for ``Result'' class operators

This chapter concerns the ruby extension only!

One class and some ruby methods are directly defined in ruby language. This part of the programming concerns the operators in which the second argument is a ``Result'' object, but the first argument has another type (Real, Complex, Array...). Then, a ruby type coercion is performed thanks to the ``Result'' class ``coerce'' method. This small part of code allows to perform the operations using the different ``Post.op???'' methods.

This part of FeResPost is programmed in the ``FeResPost.rb'' file. content looks as follows:

# encoding: utf-8

require "FeResPost.so"

module FeResPost
    class ROpResult
        @x=nil
        def initialize(res)
            @x=res
        end
        def +(other)
            return Post.opAdd(other,@x)
        end
        def -(other)
            return Post.opSub(other,@x)
        end
        def *(other)
            return Post.opMul(other,@x)
        end
        def /(other)
            return Post.opDiv(other,@x)
        end
        def **(other)
            return Post.pow(other,@x)
        end
    end
    class Result
        def coerce(x)
            [ROpResult.new(self),x]
        end
    end # Result
end # FeResPost 

puts "End \"FeResPost\" module initialization.\n"
puts "\n\n"



FeResPost User Manual Version 4.4.2 (2018/01/01)