Need help to understand how the marked <<< def works. Thanks

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

#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
-- 
Posted via http://www.ruby-forum.com/.