Attributes in class

  • Thread starter Amir Ebrahimifard
  • Start date
A

Amir Ebrahimifard

Hi
Please help someone that knows C++ , and my question :
Does "attribute" in ruby is same as "private member" in c++ ? if no
please exactly explain me what is the concept of "attribute" in ruby?
 
S

Sniper Abandon

Amir said:
Hi
Please help someone that knows C++ , and my question :
Does "attribute" in ruby is same as "private member" in c++ ? if no
please exactly explain me what is the concept of "attribute" in ruby?

i thing you are talking about rails model
attribute is a instance variable of that class
 
B

Brian Candler

Amir said:
Hi
Please help someone that knows C++ , and my question :
Does "attribute" in ruby is same as "private member" in c++ ? if no
please exactly explain me what is the concept of "attribute" in ruby?

You're perhaps thinking of accessor methods. The following code:

class Foo
attr_accessor :bar
end

does effectively the same as this:

class Foo
def bar
@bar
end
def bar=(val)
@bar = val
end
end

For learning about the basics of Ruby, I strongly recommend the book
Programming Ruby. The first edition is available to view online for
free:
http://www.ruby-doc.org/docs/ProgrammingRuby/

Since you're already a programmer you should find this very accessible.

HTH,

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top