Attr_accessor:
You can declare the attributes for the ruby class using the keyword 'attr_accessor'.
While initializing object you can assign the value to it. Check the following example and practice it.
- class Person
- attr_accessor :name
- def initialize(name)
- self.name = name
- end
- end
- person = Person.new("Andreas")
- puts person.name
- person.name = "David"
- puts person.name
- Hope you will practice it, i will get back to you with new concept.
Ruby tutorial session 5
Subscribe to:
Comments (Atom)
My Experience in RUBYCONF INDIA 2016
Hi Readers, Rubyconf India is a global event complementing other RubyConf events across the world. I attended this event held on 19-20 ma...
-
Visit the video: Ruby creator(Yukihiro Matsumoto) talk in Rubyconf India
-
Hi Amigos, Today i would like to share something which i achieved today. There is one Post i saw few days back in Facebook. What th...
-
In my previous posts you learn about the class and inheritance Now we are going to get the information regarding the setter and getter...
No comments:
Post a Comment