Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErickGodoy--Practice2 #22

Open
wants to merge 2 commits into
base: practice-day4
Choose a base branch
from

Conversation

ErickGodoyWizeline
Copy link

No description provided.

attr_accessor :file
@modes = %i[reader writer both]

def initialize
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could delete the empty constructor def initialize with any issue

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be also initializated like def initialize; end.

end

def create_file(path_file)
File.new(path_file,'w') if !File.exist?(path_file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use unless over if with negatives conditions. File.new(path_file,'w') unless File.exist?(path_file)

end

def read_file(lines: false)
lines ? data = self.file&.read : data = self.file&.readlines.map(&:chomp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not necessary to declare the function data, just need self.file&.read

end

def write_file(data: nil, append: true)
append ? File.write(self.file, data, mode: "a") : File.write(self.file, data)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within this scope you could remove self statement

archiver.create_file('test.txt')
archiver.open_file_as_both('test.txt')
archiver.write_file(data: 'Put this into a file each time.', append: true)
p archiver.read_file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra empty line at the end of the file is taken as a good practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants