Michael Fellinger
7/13/2008 9:47:00 PM
On Mon, Jul 14, 2008 at 4:18 AM, Luiz Vitor Martinez Cardoso
<grabber@gmail.com> wrote:
> I'm learning Ruby, and i need to solve a problem:
>
>
> class Person
> def namer=(name, surname)
> @var = name
> @car = surname
> end
> end
>
> object = Person.new
> object.namer = (how to pass the params here) ?
Usually it's better to do this via initialize
class Person
def initialize(name, surname)
@name, @surname = name, surname
end
end
Person.new('Max', 'Mustermann')
You can combine that with attr_accessor
class Person
attr_accessor :name, :surname
def initialize(name = nil, surname = nil
@name, @surname = name, surname
end
end
person = Person.new('Max')
person.surname = 'Mustermann'
> Thanks for your attention!