0

Hey, I'm learning Ruby and I've just about got it sorted. I have just one (or maybe more) question(s): What is marshal.dump and does it allow you to save data to a file outside of the Ruby program? If not, how do I create saved data (ie. character attributes inside a text-based game)? Thanks for answers!

3
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by Gazco
0

Hey, I'm learning Ruby and I've just about got it sorted. I have just one (or maybe more) question(s): What is marshal.dump and does it allow you to save data to a file outside of the Ruby program? If not, how do I create saved data (ie. character attributes inside a text-based game)? Thanks for answers!

For some reason the rubycentral site seems to be down so the original article I'd link to isn't available, however it's in the google cache.

0

Hey, I'm learning Ruby and I've just about got it sorted. I have just one (or maybe more) question(s): What is marshal.dump and does it allow you to save data to a file outside of the Ruby program? If not, how do I create saved data (ie. character attributes inside a text-based game)? Thanks for answers!

You can read this small tutorial here -
http://sitekreator.com/satishtalim/object_serialization.html

Hope that helps.

0

Thanks, these sites really helped a lot and answered my questions, but the last one also brought up one little one: in the second example the programmer used

File.open('game', 'w+') do |f|

What does the string

'w+'

do and

|f|

do please? Thanks once again for any help.

0

Thanks, these sites really helped a lot and answered my questions, but the last one also brought up one little one: in the second example the programmer used

File.open('game', 'w+') do |f|

What does the string

'w+'

do and

|f|

do please? Thanks once again for any help.

"w+" is a mode string; it truncates the file (or creates a new one if it doesn't exist)

|f| is a block. Basically it means that in the following code f refers to the file.

A quick example of a simple block:

>> 5.times do |i|
?> puts i.to_s
>> end
0
1
2
3
4
=> 5
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.