Google Groups Home
Help | Sign in
Message from discussion Container wont contain! (noob question)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
7stud --  
View profile
 More options May 11, 5:18 pm
Newsgroups: comp.lang.ruby
From: 7stud -- <bbxx789_0...@yahoo.com>
Date: Sun, 11 May 2008 16:18:06 -0500
Local: Sun, May 11 2008 5:18 pm
Subject: Re: Container wont contain! (noob question)

Extreme Noob wrote:
> Wow, didn't know about that =() function. Thanks for the help

Look at this class:

class Dog
  def initialize(name)
    @name = name
  end

  def name=(a_name)
    @name = a_name
  end

  def name
    return @name
  end
end

d = Dog.new("Spot")
puts d.name

d.name = "Rover"
puts d.name

The Dog class above is equivalent to:

class Dog
  attr_accessor :name

  def initialize(name)
    @name = name
  end

end

In other words,  the line:

attr_accessor :name

creates the methods "name=" and "name" for you.
--
Posted via http://www.ruby-forum.com/.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google