class Person attr_accessor :name def initialize(name) self.name = name end end def change_name(new_name, thing) thing.name = new_name if thing.respond_to?(:name=) end
- class Person
- attr_accessor :name
- def initialize(name)
@name = name- self.name = name
- end
- end
- def change_name(new_name, thing)
if thing.respond_to?(:name=)# do somethingthing.name = new_nameelsenilend- thing.name = new_name if thing.respond_to?(:name=)
- end