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.
Asked
Active
Viewed 500 times
0
-
Instead of copy&paste, read that file, e.g [File.foreach](http://www.ruby-doc.org/core-2.1.5/IO.html#method-c-foreach) – blelump Dec 04 '14 at 08:59
2 Answers
3
Just add an empty string after that.
my_str = "paste here";""
Or mute the irb echo by setting
conf.echo = false

Siva
- 7,780
- 6
- 47
- 54
-
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. – tekina Dec 04 '14 at 11:39
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

Arun Eapachen
- 119
- 4