Wiki

Changes between Version 8 and Version 9 of AllOfCobraInOnePage

Show
Ignore:
Timestamp:
01/06/14 12:24:45 (10 years ago)
Author:
kobi7
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AllOfCobraInOnePage

    v8 v9  
    7171}}} 
    7272 
     73 
     74mixin example: 
     75{{{ 
     76 
     77mixin VolumeSupport 
     78    pro volume from var as int 
     79    def decVolume 
     80        .volume = Math.max(0, .volume - 1) 
     81 
     82    def incVolume 
     83        .volume = Math.min(100, .volume + 1) 
     84 
     85}}} 
     86 {{{ 
     87class Radio adds VolumeSupport   
     88    cue init 
     89        base.init 
     90        .volume = 0 
     91 
     92}}}  
     93{{{ 
     94class TV adds VolumeSupport      
     95    cue init 
     96        base.init 
     97        .volume = 0 
     98}}}  
     99{{{ 
     100class Program 
     101    def main 
     102        r = Radio() 
     103        assert r.volume == 0 
     104        r.incVolume 
     105        assert r.volume == 1 
     106 
     107}}}