10. -------------------------------------------------------------- File::new
File.new(filename, mode="r") => file
File.new(filename [, mode [, perm]]) => file
------------------------------------------------------------------------
Opens the file named by _filename_ according to _mode_ (default is
``r'') and returns a new +File+ object. See the description of
class +IO+ for a description of _mode_. The file mode may
optionally be specified as a +Fixnum+ by _or_-ing together the
flags (O_RDONLY etc, again described under +IO+). Optional
permission bits may be given in _perm_. These mode and permission
bits are platform dependent; on Unix systems, see +open(2)+ for
details.
f = File.new("testfile", "r")
f = File.new("newfile", "w+")
f = File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
11. ruby 1.8.8dev (2009-11-19 revision 25863) [i386-darwin9.8.0]
File.new
- returns a new File with mode string
- returns a new File with mode num
- returns a new File with modus num and permissions
- creates the file and returns writable descriptor when called with 'w' mode and r-o permissions
- opens the existing file, does not change permissions even when they are specified
- returns a new File with modus fd
- creates a new file when use File::EXCL mode
- raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL
- creates a new file when use File::WRONLY|File::APPEND mode
- raises an Errno::EINVAL error with File::RDONLY|File::WRONLY
- creates a new file when use File::WRONLY|File::TRUNC mode
- coerces filename using to_str
- raises a TypeError if the first parameter can't be coerced to string
- raises a TypeError if the first parameter is nil
- raises an Errno::EBADF if the first parameter is an invalid file descriptor
- raises an ArgumentError when it receives more than three parameters
- opens directories
Finished in 0.025401 seconds
1 file, 17 examples, 32 expectations, 0 failures, 0 errors
27. Rubyspec
describe "File.new" do
it "returns a new File with mode string" do
@fh = File.new(@file, 'w')
@fh.class.should == File
File.exists?(@file).should == true
end
end
MSpec is a specialized framework that is syntax-compatible with RSpec for basic things like describe, it blocks and before, after actions.
MSpec contains additional features that assist in writing the RubySpecs used by multiple Ruby implementations. Also, MSpec attempts to use the simplest Ruby language features so that beginning Ruby implementations can run it.
EL PRIMERO ES EL EXTERNAL
AL LEER EL FICHERO LO TRADUCE AUTOMATICAMENTE