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

Subsections


I.7 Modification of Standard classes

Two standard classes may also be modified in FeResPost: the ``Float'' class and the ``Array'' class; the operators are modified in such a way that the second operand may be a ``Result'' object. If the second operand is not a Result object, the default version of the operator is called. Table I.7.1 summarizes the modifications in these classes.


Table I.7.1: Methods modified in standard classes.
Modification of ``Float'' class
Method name Description Example
+ I.7.1 --
- I.7.1 --
* I.7.1 --
/ I.7.1 --
Modification of ``Array'' class
Method name Description Example
+ I.7.1 --
- I.7.1 --
* I.7.1 --
/ I.7.1 --

Practically, the modification of standard classes is done in ruby file ``modifStdClasses.rb''. Until version 3.2.7 of FeResPost, the modification was done in the compiled library. Now the fact that the modification of standard classes is done with ruby statements allows the user to cancel these modifications, for example by erasing the corresponding lines in the ``FeResPost.rb'' file of the distribution. The file would then look as follows:

    if (RUBY_PLATFORM.include?("win")) then
        require "FeResPost.dll"
    else
        require "FeResPost.so"
    end

    #require "modifStdClasses"
      
    STDOUT.printf("End \"FeResPost\" module initialization.\n")
    STDOUT.printf("\n\n")
    STDOUT.flush
The reason why the modification of standard classes is displaced into a ruby source file rather than in the compiled part of the extension is that one tries to maintain the compiled library in line with the COM component. Moreover, it is not very good practice to modify standard classes in a programming language.


I.7.1 Operators in modified standard classes

The two classes that are modified are ``Float'' and ``Array'' classes. In each case, when an operator is called, the corresponding ``Operator'' method in ``Post'' Module is called. for example, the two following statements are equivalent:

    z=x+y
    z=Post.opAdd(x,y)
Actually, this is true only if $ x$ is an object of the class ``Float'' or ``Array''.

I.7.2 How the standard classes are modified

Practically, the modification of standard classes is done in two steps:

  1. An alias is created for the old version of the operator.
  2. A new operator is created. In the definition of the operator, one tests the second operand to call the appropriate version of the operator, which may be the old one.
The following lines illustrate the modification for the addition operator of the ``Float'' class.
class Float
    
    alias _FeFesPost_old_opAdd +
    ...
    
    def +(second)
        if second.class==Result then
            return Post.opAdd(self,second)
        else
            return self._FeFesPost_old_opAdd(second)
        end
    end
    
    ...
    
end # Float


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