+ 6

In Ruby what's the difference between doing @name or self.name ?

class Person attr_accessor :name, :age def initialize(name, age) @name = name @age = age end def change(n, a) self.name = n @age = a end end p = Person.new("David", 28) p.change("Bob", 42) puts p.name puts p.age #Output Bob 42

18th Aug 2017, 5:08 PM
El CHR of MRD
El CHR of MRD - avatar
1 Réponse