IT Community - Software Programming, Web Development and Technical Support

Marshal.dump?

This is a discussion on Marshal.dump? within the Ruby forums, part of the Web Development category; how do you use marshal.dump in Ruby please?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Ruby

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-12-2007, 11:19 PM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Question Marshal.dump?

how do you use marshal.dump in Ruby please?
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-22-2007, 02:33 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Smile Re: Marshal.dump?

Hi,

Marshal.dump to save a serialized version of it to the disk.

Java features the ability to serialize objects, letting you store them somewhere and reconstitute them when needed. Ruby calls this kind of serialization marshaling.

We will write a basic class myrub.rb just for testing marshalling.

Code:
class GameCharacter

  def initialize(power, type, weapons)

    @power = power

    @type = type

    @weapons = weapons

  end

    attr_reader :power, :type, :weapons

end
The program myrubdump.rb creates an object of the above class and then uses Marshal.dump to save a serialized version of it to the disk.

Code:
require 'myrub.rb'

gc = GameCharacter.new(120, 'Magician', ['spells', 'invisibility'])

puts gc.power.to_s + ' ' + gc.type + ' '

gc.weapons.each do |w|

  puts w + ' '

end

 

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

  Marshal.dump(gc, f)

end
The program myrubload.rb uses Marshal.load to read it in.

Code:
require 'myrub.rb'

File.open('game') do |f|

      @gc = Marshal.load(f)

end

 

puts @gc.power.to_s + ' ' + @gc.type + ' '

@gc.weapons.each do |w|

  puts w + ' '

end
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-28-2007, 01:19 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Cool Re: Marshal.dump?

Ya…thnx for your reply mobile…

But I have some doubts in your coding…

You said in your coding…

Code:
File.open('game', 'w+') do |f|
What does the string

Code:
'w+'
do and

Code:
|f|
do please?
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql database dump tips and tricks write2ashokkumar Database Support 31 12-14-2007 10:54 PM
Importing mysql dump file to my Local Server Murali Database Support 1 12-12-2007 06:10 AM
Why does the JVM crash with a core dump or a Dr.Watson error? oxygen Java Programming 1 07-26-2007 04:03 AM
How to import MySQL Dump files? kingmaker Database Support 2 07-24-2007 03:47 AM
mysql dump JSureshkumar PHP Programming 3 03-14-2007 03:55 AM


All times are GMT -7. The time now is 12:16 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0