On 30.11.2007 19:54, Nathan Viswa wrote:
> Need help to understand how the marked <<< def works. Thanks

What does this have to do with the subject?  For all I can see we are 
dealing with instance methods here.

> class Person
>   def initialize(lname, fname)
>     @lname = lname
>     @fname = fname
>   end
> 
>   def lname
>     return @lname
>   end
> 
>   def fname
>     return @fname
>   end
> 
>   def lname=(myarg)          # see = <<<
>     @lname = myarg
>   end
> 
>   def fname=(myarg)
>     @fname = myarg
>   end
> end
> 
> steve = Person.new("Litt", "Stove")
> print "My name is ", steve.fname, " ", steve.lname, ".\n"
> steve.fname = "Steve"
> print "My name is ", steve.fname, " ", steve.lname, ".\n"
> 
> steve = Person.new("Litt", "Stove")
> 
> print "My name is ", steve.fname, " ", steve.lname, ".\n"
> steve.fname = "Steve"
> print "My name is ", steve.fname, " ", steve.lname, ".\n"
> 
> #steve.fname("Steve") # err
> 
> #steve.lname("Nathan") # err  ????
> steve.lname() #
> print "My name is ", steve.fname, " ", steve.lname, ".\n"
> 
> steve.lname = "Nat" #
> print "My name is ", steve.fname, " ", steve.lname, ".\n"
> 
> steve.lname() #
> print "My name is ", steve.fname, " ", steve.lname, ".\n"
> 
> 
> I:\RubyNV>zzz-tut13-class.rb
> My name is Stove Litt.
> My name is Steve Litt.
> My name is Steve Litt.
> My name is Steve Nat.
> My name is Steve Nat.
> 
> I:\RubyNV>
> 
> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> 
> if i use it stand alone it does not work!!
> 
> class Person
>   def initialize(lname)
>     @lname = lname
>   end
> 
>   def lname=(myarg)      # see = <<<
>     @lname = myarg
>        end
> 
> end
> 
> steve = Person.new("Viswa")
> 
> #puts steve.lname, 'x1' # err undefined methid lname
> #puts steve.lname(), 'x2' # err as above
> #puts steve.lname("nv"), 'x2' # err as above

Well, if you do not define those methods, they are not there.

> #steve.lname = "Nat" #
> 
> #puts steve.lname, 'x2' #  err undefined methid lname
> #puts steve.lname(), 'x3' # # err undefined methid lname
> 
> #steve.lname = "Nat" #
> #print "My name is ", steve.lname, ".\n" #err
> 
> #steve.lname() # err
> #print "My name is ", steve.lname, ".\n"# err

For a read write attribute you need to define *both* methods. 
Assignment and query.

def foo=(x) @foo=x end
def foo; @foo end

Or, much simpler in a class

attr_accessor :foo

Kind regards

	robert