开发者

delegation example cursed?

I'm trying to run the DelegateClass example from http://ruby-doc.org/stdlib/libdoc/delegate/rdoc/files/delegate开发者_C百科_rb.html

Here is the code:

require 'delegate'
require 'tmpdir'

class TmpFile < DelegateClass(File)
  def initialize(basename, tmpdir=Dir.tmpdir)
    @tmpfile = File.new("#{tmpdir}/#{basename}.tmp", File::RDWR|File::CREAT|File::EXCL, 0600)
    super(@tmpname)
  end
end

What I get in irb is

artem:~/projects/weatherdiff (master)$ irb
irb(main):001:0> require 'test.rb'
=> true
irb(main):002:0> t = TmpFile.new 'ttttt'
=> nil

Looks like one of those arcane wtfs programmers are doomed to face every now and then. Alternatively, I'm missing something blindingly obvious.


Did you mean super(@tmpfile) rather than super(@tmpname) ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜