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...
-
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...
-
Hi Readers, Rubyconf India is a global event complementing other RubyConf events across the world. I attended this event held on 19-20 ma...
-
Ruby Class: class Person def initialize(name) @name = name end def say_hi puts "#{@name} says hi...
No comments:
Post a Comment