Skip to content

File subclass doesn't pass arguments from open to new properly #7847

@djberg96

Description

@djberg96

jruby 9.4.3.0 (3.1.4) 2023-06-07 3086960 OpenJDK 64-Bit Server VM 14.0.2+12-46 on 14.0.2+12-46 +jit [x86_64-darwin]

I've got some code where I've subclassed File and altered the constructor. The call to .new works as expected. However, a call to open results in an error with JRuby. It works as expected with MRI. The following code demonstrates the problem:

class File::Temp < File
  def initialize(delete: true, **options)
    path = File.join(Dir.pwd, 'rb_file_temp_XXXXXX')
    options[:mode] ||= 'wb+'
    super(path, **options)
  end
end

# This works
fh = File::Temp.new(:delete => false)
fh.puts "hello"
fh.close

# This doesn't -> ArgumentError: wrong number of arguments (given 1, expected 0)
File::Temp.open(:delete => false){ |fh| fh.puts "world" }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions