[#408634] How do I make lots of classes aware of each other? — "Andrew S." <lists@...>

I'm apparently missing something fundamental in my knowledge of classes

10 messages 2013/07/02

[#408712] Ruby web service with REST support — "Shubhada S." <lists@...>

Hi All,

17 messages 2013/07/05

[#408812] create variables depending on counter — stefan heinrich <lists@...>

Hi community,

21 messages 2013/07/09

[#408854] execute commands within SMTP email code: send content in variables and not actual variables — dJD col <lists@...>

I am trying to send an email using the code below. I am able to send the

9 messages 2013/07/10

[#409031] tap { break } idiom deserves its own Kernel method? — Andy Lowry <lists@...>

I use this idiom from time to time:

13 messages 2013/07/22

[#409072] Link To Masses Of External Data In Openoffice? — "Austin J." <lists@...>

This is what I want to do.

19 messages 2013/07/23
[#409102] Re: Link To Masses Of External Data In Openoffice? — Tamara Temple <tamouse.lists@...> 2013/07/24

[#409103] Re: Link To Masses Of External Data In Openoffice? — "Austin J." <lists@...> 2013/07/25

tamouse m. wrote in post #1116598:

[#409122] Re: Link To Masses Of External Data In Openoffice? — Tamara Temple <tamouse.lists@...> 2013/07/26

[#409142] Re: Link To Masses Of External Data In Openoffice? — "Austin J." <lists@...> 2013/07/26

tamouse m. wrote in post #1116750:

[#409073] class <=> module — Bráulio Bhavamitra <lists@...>

Hello all,

17 messages 2013/07/23

[#409104] Ruby newbie question on Methods (NoMethoderror) — "Crispian A." <lists@...>

I have recently started learning ruby and so I am writing a small little

10 messages 2013/07/25

[#409170] Working through Ch.10 for learning to program 2.0 (Chris Pine) — JD JD <lists@...>

So, I have been working through this book, and have been doing ok up

33 messages 2013/07/28
[#409195] Re: Working through Ch.10 for learning to program 2.0 (Chris Pine) — Harry Kakueki <list.push@...> 2013/07/29

I tried this and came up with a one-liner that seems to do it. It sorts the

[#409258] WATIR - ScriptError popup on IE - Unable to get rid of! — Graeme Halls <lists@...>

I am new to Ruby & Watir, and I am having a nightmare with IE and Script

11 messages 2013/07/31

including FileUtils::Verbose crashes Marshal.dump

From: Bryan Lockwood <lockwood.bryan@...>
Date: 2013-07-01 16:22:01 UTC
List: ruby-talk #408620
This is a bug I ran into today. I'm not sure who's responsible for fixing it, but I don't personally feel up to 
the task. I could make it a multi-day project I suppose, but I feel I have better things to do today, and tomorrow, 

I'm posting this here in hopes that someone who reads this list will know what to do to fix it.

The bug exists in 1.9.2, 1.9.3, and 2.0.0.

I had written a class for vocabulary cards, which I Marshal.dump'ed at the end of each session.  Then I thought that
before I casually dumped the list a second or subsequent time, I should make sure that, should anything bad happen, 
I didn't completely clobber the dump file. So, using fileutils, I made a backup copy before dumping, and then removed
it if things went well, or used it to restore the original file if things didn't go well.

I found the dump worked the first time, but each in each subsequent session the dump would fail, evidently because
somewhere in my object graph an IO had crept in as an instance variable. I was pretty sure I hadn't done that, so I had
to write some code to traverse the code and look for an IO somewhere. I found it, and present for your perusal a small test
file that illustrates the problem.

My problem was that I read about fileutils in the pickaxe book (for 1.9 and 2.0), and the example included FileUtils::Verbose,
and I figured that would be fine for starters, as I could then see what it was doing.

If you copy this to a file and run it, the first time it will not find the file ("aFoo"), won't perform the backup, and will successfully
dump the object to the file. The second time, however, it will find the find, use FileUtil's cp to make a backup copy, and then
try unsuccessfully to dump the file, which fails because the object contains an instance of IO. In the example, I catch this
exception and then go on to list the instance variables, and Whoa!, what the devil are those instance variables "@filutiils_label"
and "@fileutils_output" doing there?

So evidently calling the verbose version of FileUtils#cp creates, unbeknownst to the user, a few instance variables for its own
use. I suggest there must be a better place to keep this information. The problem goes away entirely if you just include FileUtils and
not FileUtils::Verbose.

Thanks for listening, here's the file. Have a nice day,

Bryan

-------------------------------------------
#!/usr/bin/env ruby
require 'fileutils'
include FileUtils::Verbose

class Foo
  def initialize(str)
    @foo = str
  end
  
  def make_backup_copy
    cp(@foo, "#{@foo}.back") if File.exist?(@foo)
  end
  
  def dump_to_file
    make_backup_copy
    puts "dumping to file #{@foo}"
    begin
      File.open(@foo, "w") { |file| Marshal.dump(self, file) }
    rescue Exception => exc
      puts exc
      return
    end
    puts "dumped to file #{@foo}"
  end
  
end
f = Foo.new("aFoo")
f.dump_to_file
puts "instance variables are now #{f.instance_variables}"
-------------------------------------------
and here's the output from running it twice:

18:18 cards:>./tester.rb 
dumping to file aFoo
dumped to file aFoo
instance variables are now [:@foo]
18:18 cards:>./tester.rb 
cp aFoo aFoo.back
dumping to file aFoo
can't dump IO
instance variables are now [:@foo, :@fileutils_output, :@fileutils_label]



In This Thread

Prev Next