Search code examples
pharo

How do I specify different getter and setter accessors for a Description in Magritte?


By convention you specify only the accessor: and Magritte uses the same name for both. Some comments in the code and in the http://book.seaside.st say that it supports having getters and setters with different names. How?


Solution

  • You can use a MAPluggableAccessor, something like this:

    descriptionMonths
        <magritteDescription>
    
        ^ MANumberDescription new 
            priority: 30;
            label: 'Months';
            accessor: (MAPluggableAccessor 
                read: [ :this | this periodMonths ]
                write: [ :this :monthsNumber | this periodMonths: monthsNumber ]);
            yourself