开发者

delegation example cursed?

开发者 https://www.devze.com 2022-12-21 10:33 出处:网络
I\'m trying to run the DelegateClass example from http://ruby-doc.org/stdlib/libdoc/delegate/rdoc/files/delegate开发者_C百科_rb.html

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

精彩评论

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

关注公众号