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.
No comments:
Post a Comment