Attributes in class

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?

Amir E. wrote:

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

Amir E. wrote:

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs