943,999 Members | Top Members by Rank

Ad:
  • Ruby Discussion Thread
  • Marked Solved
  • Views: 8357
  • Ruby RSS
Apr 22nd, 2007
0

how do you use marshal.dump in Ruby please?

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Gazco is offline Offline
8 posts
since Mar 2007
Apr 22nd, 2007
0

Re: how do you use marshal.dump in Ruby please?

Click to Expand / Collapse  Quote originally posted by Gazco ...
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.
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005
Apr 22nd, 2007
0

Re: how do you use marshal.dump in Ruby please?

Click to Expand / Collapse  Quote originally posted by Gazco ...
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/o...alization.html

Hope that helps.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
IndianGuru is offline Offline
9 posts
since Apr 2007
Apr 23rd, 2007
0

Re: how do you use marshal.dump in Ruby please?

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
Ruby Syntax (Toggle Plain Text)
  1. File.open('game', 'w+') do |f|
What does the string
Ruby Syntax (Toggle Plain Text)
  1. 'w+'
do and
Ruby Syntax (Toggle Plain Text)
  1. |f|
do please? Thanks once again for any help.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Gazco is offline Offline
8 posts
since Mar 2007
Apr 23rd, 2007
0

Re: how do you use marshal.dump in Ruby please?

Click to Expand / Collapse  Quote originally posted by Gazco ...
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
Ruby Syntax (Toggle Plain Text)
  1. File.open('game', 'w+') do |f|
What does the string
Ruby Syntax (Toggle Plain Text)
  1. 'w+'
do and
Ruby Syntax (Toggle Plain Text)
  1. |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:

Ruby Syntax (Toggle Plain Text)
  1. >> 5.times do |i|
  2. ?> puts i.to_s
  3. >> end
  4. 0
  5. 1
  6. 2
  7. 3
  8. 4
  9. => 5
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005
Apr 24th, 2007
0

Re: how do you use marshal.dump in Ruby please?

Thank you this really helps!
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Gazco is offline Offline
8 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Ruby Forum Timeline: Ruby, Rails Job sites - Resource
Next Thread in Ruby Forum Timeline: What do you think of Ruby?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC