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
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)
@surname = surname
@name = name
@patronymic = patronymic
@id = id
@phone = phone
@telegram = telegram
@email = email
@git = git
def initialize(args = {})
@surname = args.fetch(:surname)
@name = args.fetch(:name)
@patronymic = args.fetch(:patronymic)
@id = args[:id] || nil
@phone = args[:phone] || nil
@telegram = args[:telegram] || nil
@email = args[:email] || nil
@git = args[:git] || nil
end
def to_s

Loading…
Cancel
Save