Forum: Ruby Restore a marshall file .

8e363d51ab9c40050e4f2fdb4ea95887?d=identicon&s=25 Chuck N. (chuck_n)
on 2013-10-30 16:11
Hello I'm trying to learn ruby, and I have a question, how can I restore
a file marshall. That is to say retrieve the original file. Thank you in
advance, ruby is the first programming laguage I try to 'learn, so
please give me a clear answer . I'm French sorry for my bad english

Thanks,
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-10-30 16:28
(Received via mailing list)
On Wed, Oct 30, 2013 at 4:11 PM, Chuck N. <lists@ruby-forum.com> wrote:
> Hello I'm trying to learn ruby, and I have a question, how can I restore
> a file marshall. That is to say retrieve the original file. Thank you in
> advance, ruby is the first programming laguage I try to 'learn, so
> please give me a clear answer . I'm French sorry for my bad english

irb(main):004:0> x = rand(1000).to_s
=> "662"
irb(main):005:0> File.open("data.bin", "wb") {|io| Marshal.dump(x, io)}
=> #<File:data.bin (closed)>
irb(main):006:0> y = File.open("data.bin", "rb") {|io| Marshal.load(io)}
=> "662"
irb(main):007:0> x.equal? y
=> false
irb(main):008:0> x.object_id
=> 12886726380
irb(main):009:0> y.object_id
=> 12886713020

In this example "x" is just a sample value - could be any object.

Kind regards

rober
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-10-30 17:00
I tried using Marshal with my RubyExcel gem in IRB, and I got these
warnings:

(irb):6: warning: RubyExcel::Sheet#respond_to?(:marshal_dump) is old
fashion which takes only one parameter
C:/splice/bin/RubyExcel/lib/lib/rubyexcel/sheet.rb:430: warning:
respond_to? is defined here

My Google search didn't turn up anything particularly relevant. Is this
warning part of IRB, Marshal... Ruby interpreter?
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2013-10-30 17:29
(Received via mailing list)
On 10/30/2013 09:00 AM, Joel Pearson wrote:
>
It's a warning from Ruby:

https://github.com/ruby/ruby/blob/fb3bd5a18a335b0f...

Change is here:
https://github.com/ruby/ruby/commit/a106b310e5bbe6...

Marshal calls rb_respond_to() which calls rb_obj_respond_to() which
issues that warning if an object's respond_to? method doesn't accept an
optional second argument:

$ irb
2.0.0p247 :001 > class A
2.0.0p247 :002?>   def respond_to? meth
2.0.0p247 :003?>     end
2.0.0p247 :004?>   end
  => nil
2.0.0p247 :005 > Marshal.dump(A.new)
(irb):5: warning: A#respond_to?(:marshal_dump) is old fashion which
takes only one parameter
(irb):2: warning: respond_to? is defined here
(irb):5: warning: A#respond_to?(:_dump) is old fashion which takes only
one parameter
(irb):2: warning: respond_to? is defined here
  => "\x04\bo:\x06A\x00"
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.