Class: File

encoding: utf-8

Public Visibility

Public Class Method Summary

add(file, *chunks)

Append given chunks to the existing file or create new one.

Returns: String

append(file, *chunks)

Append given chunks to the existing file or create new one.

Returns: String

print(file, *chunks)

Create new file and write there given chunks.

Returns: String

puts(file, *chunks)

Create new file and write there given chunks.

Returns: String

write(method, mode, file, *args)

Write data to file with given method.

Returns: String

Public Instance Methods Inherited from Object

define_instance_method, not_nil?, try

Public Class Method Details

add

public String add(file, *chunks)

Append given chunks to the existing file or create new one. It use IO#print for write to given file.

Meta Tags

Parameters:

Returns:

[String]

Expanded path to given file

Raises:

[Errno::ENOENT]

If parent directory of given file doesn’t exist

[Errno::EACCES]

If you don’t have permissions to write to given file

Author:

Botanicus

Since:

0.0.3

[View source]


28
29
30
# File 'lib/rango/ext/file.rb', line 28

def self.add(file, *chunks)
  self.write(:print, "a", file, *chunks)
end

append

public String append(file, *chunks)

Append given chunks to the existing file or create new one. It use IO#puts for write to given file.

Meta Tags

Parameters:

Returns:

[String]

Expanded path to given file

Raises:

[Errno::ENOENT]

If parent directory of given file doesn’t exist

[Errno::EACCES]

If you don’t have permissions to write to given file

Author:

Botanicus

Since:

0.0.3

[View source]


14
15
16
# File 'lib/rango/ext/file.rb', line 14

def self.append(file, *chunks)
  self.write(:puts, "a", file, *chunks)
end

print

puts

public String puts(file, *chunks)

Create new file and write there given chunks. It use IO#puts for write to given file.

Meta Tags

Parameters:

Returns:

[String]

Expanded path to given file

Raises:

[Errno::ENOENT]

If parent directory of given file doesn’t exist

[Errno::EACCES]

If you don’t have permissions to write to given file

Author:

Botanicus

Since:

0.0.3

[View source]


42
43
44
# File 'lib/rango/ext/file.rb', line 42

def self.puts(file, *chunks)
  self.write(:puts, "w", file, *chunks)
end

write

public String write(method, mode, file, *args)

Write data to file with given method.

Meta Tags

Parameters:

Returns:

[String]

Expanded path to given file

Raises:

[Errno::ENOENT]

If parent directory of given file doesn’t exist

[Errno::EACCES]

If you don’t have permissions to write to given file

Author:

Botanicus

Since:

0.0.3

[View source]


69
70
71
72
73
# File 'lib/rango/ext/file.rb', line 69

def self.write(method, mode, file, *args)
  self.expand_path(file).tap do |path|
    self.open(path, mode) { |file| file.send(method, *args) }
  end
end