refactor: modify Student constructor to accept arguments as a hash for flexibility

main
Artem-Darius Weber 4 months ago
parent 5293a4c0e7
commit 3161870add

@ -1,15 +1,17 @@
class Student class Student
attr_accessor :id, :surname, :name, :patronymic, :phone, :telegram, :email, :git attr_accessor :id, :surname, :name, :patronymic, :phone, :telegram, :email, :git
def initialize(surname:, name:, patronymic:, id: nil, phone: nil, telegram: nil, email: nil, git: nil) def initialize(args = {})
@surname = surname @surname = args.fetch(:surname)
@name = name @name = args.fetch(:name)
@patronymic = patronymic @patronymic = args.fetch(:patronymic)
@id = id
@phone = phone
@telegram = telegram @id = args[:id] || nil
@email = email @phone = args[:phone] || nil
@git = git @telegram = args[:telegram] || nil
@email = args[:email] || nil
@git = args[:git] || nil
end end
def to_s def to_s

Loading…
Cancel
Save