From: "Sandor Szücs" Date: 2013-08-06T19:40:13+02:00 Subject: Re: Saving with yaml On 8/6/13 5:41 PM, Green Eco wrote: > Hi, > > I have a question. :-) I have already found a lot in the web but that > does not really helped me. This far my code looks like this: > > > to save: > > require "yaml" > > @characters = ["Molly", "Trade"] > @saves = {location: "Southeaster", > hunger: 10, > life: 76 > } > @settings = {display: "1360*960", > render: "high", > saves: "manual" > } > > output = File.new("Saves.yaml", "w") do |file| > YAML.dump > end > output.write YAML.dump(@characters) # Wie sichert man mehrere For example: File.open("Saves.yaml", "w") do |file| file.write(YAML.dump(@characters)) file.write(YAML.dump(@saves)) file.write(YAML.dump(@settings)) end or File.open("Saves.yaml", "w") do |file| [@characters,@saves,@settings].each do |item| file.write(YAML.dump(item)) end end or even better: File.open("Saves.yaml", "w") do |file| file.write(YAML.dump([@characters,@saves,@settings])) end YAML.load File.read "Saves.yaml" # => [["Molly", "Trade"], {:location=>"Southeaster", :hunger=>10, :life=>76}, {:display=>"1360*960", :render=>"high", :saves=>"manual"}] -- All the best, Sandor Szücs _______________________________________________ ruby-talk mailing list ruby-talk@ruby-lang.org http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-talk