class Person
def get_age
@age
end
def set_age age
@age = age
end
end
should be refactored to:
class Person
def age
@age
end
def age= age
@age = age
end
end
Apart from using attr_accessor in those simple cases, it allows to send a more meaningful message:
person = Person.new person.age = 30 person.age
Supported by Ruby 2.1.1

Keine Kommentare:
Kommentar veröffentlichen