If your array only includes objects that are literally written such as Numerals, Strings, Arrays, Hashes, you can use eval a = 1, 2, 3. Inspect # => "1, 2, 3" eval(a) # => 1, 2, 3.
If your array only includes objects that are literally written such as Numerals, Strings, Arrays, Hashes, you can use eval. A = 1, 2, 3. Inspect # => "1, 2, 3" eval(a) # => 1, 2, 3.
That's exactly what I wanted to know. Although I went with the YAML option anyway. – Nat Jun 23 at 17:50 @Nat Good to know that.
– sawa Jun 23 at 18:20 eval() is evil and it's slow. Just saying. – Kudu Jun 23 at 23:17 I agree with Kudu, eval() is the wrong approach.
Use plaintext (Yaml, JSON) or binary (Marshal) but be very careful relying on executing arbitrary Ruby code as a form of serialization. – Seamus Abshere Jun 230 at 4:04.
In my opinion, this sounds like too much trouble. Use YAML instead. Require 'yaml' a = , , , File.
Open("output. Yml", "w") do |f| f. Write a.
To_yaml end be = YAML. Load File. Open('output.
Yml', 'r') As an alternative, you could use JSON instead.
Say you have array ary You could write the array to a file: File. Open(path, 'w') { |f| f. Write Marshal.
Dump(ary) } and then re-create the array by reading the file into a string and saying ary = Marshal. Load(File. Read(path)).
Interesting solution, but binary serialization has it's own set of issues. I try to avoid Marshal / pickle in production, resorting instead to YAML or JSON. – Kudu Jun 23 at 14:07 why is YAML better?
– Nat Jun 23 at 14:18 1 If you want a plaintext serialization format, you might want to use the yajl-ruby gem... they say it's even faster than Marshal... replace "Marshal. Dump" with "Yajl::Encoder. Encode" and "Marshal.
Load" with "Yajl::Parser. Parse" – Seamus Abshere Jun 23 at 14:33 1 Nat, binary serialization is tricky and works for one programming language only. With YAML or JSON, you can load the array into Ruby, Python, C, etc.Also, if something doesn't work the way it should, you can look at the text file to debug it, instead of parsing the binary data.
– Kudu Jun 23 at 23:15.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.