diff --git a/lab2/main.rb b/lab2/main.rb new file mode 100644 index 0000000..4a3912f --- /dev/null +++ b/lab2/main.rb @@ -0,0 +1,22 @@ +require_relative 'student' + +student1 = Student.new( + surname: 'Алексеевич', + name: 'Артем-Дариус', + patronymic: 'Вебер', + id: 1, + phone: '+79891242223', + telegram: '@alstroemeria22', + email: 'no-replay@djft.ru', + git: 'https://git.djft.ru' +) + +student2 = Student.new( + surname: 'nil', + name: 'Норакет', + patronymic: 'nil' +) + +puts student1 +puts '-' * 40 +puts student2 \ No newline at end of file diff --git a/lab2/student.rb b/lab2/student.rb index 0f24b54..46ae085 100644 --- a/lab2/student.rb +++ b/lab2/student.rb @@ -2,13 +2,22 @@ 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 + @surname = surname + @name = name + @patronymic = patronymic + @id = id + @phone = phone + @telegram = telegram + @email = email + @git = git + end + + def to_s + "Student: #{@surname} #{@name} #{@patronymic}\n" \ + "ID: #{@id || 'N/A'}\n" \ + "Phone: #{@phone || 'N/A'}\n" \ + "Telegram: #{@telegram || 'N/A'}\n" \ + "Email: #{@email || 'N/A'}\n" \ + "Git: #{@git || 'N/A'}" end end \ No newline at end of file