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

completed challenge #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

maxdignan
Copy link

No description provided.

@file = File.open(filename, "r")
@text = ''
@file.each_line do |txt|
@text = @text + txt
Copy link

Choose a reason for hiding this comment

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

@text += txt

Copy link
Author

Choose a reason for hiding this comment

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

Did not know += worked in Ruby. Good to know!

def initialize(filename)
file = File.open(filename, "r")
@text = ''
file.each_line do |txt|

Choose a reason for hiding this comment

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

Right here you're iterating over each line of the file and appending them onto @text one at a time, but there's a method you could use to just read the whole file at once and get the same result. Check out File#read

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