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?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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! |
| Sponsored Links |
| |||
| 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 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 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 |
| |||
| 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| Code: 'w+' Code: |f|
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |