feat: add to_s method in Student class for formatted output and create main.rb to instantiate and display Student objects

main
Artem-Darius Weber 4 months ago
parent 57a51641e7
commit 835a6b7738

@ -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

@ -2,13 +2,22 @@ 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(surname:, name:, patronymic:, id: nil, phone: nil, telegram: nil, email: nil, git: nil)
@surname = surname @surname = surname
@name = name @name = name
@patronymic = patronymic @patronymic = patronymic
@id = id @id = id
@phone = phone @phone = phone
@telegram = telegram @telegram = telegram
@email = email @email = email
@git = git @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
end end
Loading…
Cancel
Save