Project

General

Profile

Feature #9060

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

=begin 
 I understand assignment in ruby is assigning an object to the variable. However there are other cases we need to use assignments. For example: 

  class 

 (({class Foo 
  
 end 

  

 class Bar < Foo 
  
 end 

  

 f = Foo.new 
  
 b = Bar.new 
  
 //Some operations on b b})) 

 Now we want ((|f|)) f to contain the same data as ((|b|)). b. But if we use (({f f = b})), ((|f|)) b, f will not be (({Foo})) Foo any more. 
 Or we can define a method like (({Foo##loadFromBar})), ((*Foo##loadFromBar*)), but (({Foo})) Foo is the super class of (({Bar})) Bar and usually defined before (({Bar}))... Bar... 

 Can we have something like: 
  f 
 (({f := b b})) 
 so that ((|f|)) f will have the same shared data with ((|b|))? b? 

 And we can even load data from other classes by overloading this operator: 

  class 

 (({class Foo 
    
   def :=(f) 
      
     @data = f 
    
   end 
  
 end 
  
 f = Foo.new 
  
 f := 2.2 2.2})) 

 We can always achieve this by defining a named method, but this operator can provide some syntax sugar and convenience. 
 =end 

Back