0

I have 500+ strings in a file. If I simply copy-paste it into Rails console to assign the values to an array, it takes a lot of time(10 mins+) and the CPU usage spikes to maximum (the fans go crazy in my laptop) just to print whatever I have pasted. How can I skip that from being printed on screen because I'm sure assignment (without echo) shouldn't take more than a minute.

1
  • Instead of copy&paste, read that file, e.g File.foreach Commented Dec 4, 2014 at 8:59

2 Answers 2

3

Just add an empty string after that.

my_str = "paste here";""

Or mute the irb echo by setting

conf.echo = false
Sign up to request clarification or add additional context in comments.

1 Comment

The first one won't really work since my assignment string is really big and printing that during assignment itself takes a lot of time.
1

Use 'File' class in ruby to read the file instead of just copy pasting.

File.open("path/to/your/file").each do |file|
  file.each_line do |line|
  dat_array = line.split()
end
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.