diff --git a/lab2/contact.rb b/lab2/contact.rb index caaf745..8675da4 100644 --- a/lab2/contact.rb +++ b/lab2/contact.rb @@ -1,4 +1,5 @@ class Contact +# add setters with validation attr_reader :phone, :telegram, :email def initialize(args = {}) @@ -20,6 +21,7 @@ class Contact @phone || @telegram || @email end + # getSingleContact def info return "Phone: #{@phone}" if @phone return "Telegram: #{@telegram}" if @telegram @@ -34,6 +36,7 @@ class Contact /\A\+?[0-9]{9,15}\z/.match?(phone) end + # self def valid_telegram?(telegram) /\A@[A-Za-z0-9_]{5,32}\z/.match?(telegram) end diff --git a/lab2/person.rb b/lab2/person.rb index 0e17ac3..693ec0d 100644 --- a/lab2/person.rb +++ b/lab2/person.rb @@ -1,6 +1,7 @@ require_relative 'contact' class Person + # contact только в этом классе, убрать из наследуемых переопределение attr_reader :id, :git, :contact def initialize(id:, git:, contact: Contact.new) diff --git a/lab2/student_short.rb b/lab2/student_short.rb index 6801b1f..2abc464 100644 --- a/lab2/student_short.rb +++ b/lab2/student_short.rb @@ -1,7 +1,7 @@ require_relative 'person' class StudentShort < Person - attr_reader :surname_initials, :contact + attr_reader :surname_initials def initialize(id:, git:, surname_initials:, contact:) super(id: id, git: git, contact: contact) @@ -38,4 +38,4 @@ class StudentShort < Person def to_s "#{@surname_initials}, Git: #{@git}, Contact: #{@contact}" end -end +end \ No newline at end of file