Returns true
if the named file
exists and is a regular file.
file
can be an IO
object.
If the file
argument is a symbolic link, it will resolve the symbolic link and use the file referenced by the link.
Enables garbage collection, returning true
if garbage collection was previously disabled.
GC.disable #=> false GC.enable #=> true GC.enable #=> false
Disables garbage collection, returning true
if garbage collection was already disabled.
GC.disable #=> false GC.disable #=> true
Returns the Base64-decoded version of str
. This method complies with RFC 2045. Characters outside the base alphabet are ignored.
require 'base64' str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' + 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' + 'ZSB0aHJlZQpBbmQgc28gb24uLi4K' puts Base64.decode64(str)
Generates:
This is line one This is line two This is line three And so on...
Returns true
if the file at path new
is newer than all the files at paths in array old_list
; false
otherwise.
Argument new
and the elements of old_list
should be interpretable as paths:
FileUtils.uptodate?('Rakefile', ['Gemfile', 'README.md']) # => true FileUtils.uptodate?('Gemfile', ['Rakefile', 'README.md']) # => false
A non-existent file is considered to be infinitely old.
Related: FileUtils.touch
.
Returns true
if the file at path new
is newer than all the files at paths in array old_list
; false
otherwise.
Argument new
and the elements of old_list
should be interpretable as paths:
FileUtils.uptodate?('Rakefile', ['Gemfile', 'README.md']) # => true FileUtils.uptodate?('Gemfile', ['Rakefile', 'README.md']) # => false
A non-existent file is considered to be infinitely old.
Related: FileUtils.touch
.
Escapes a string so that it can be safely used in a Bourne shell command line. str
can be a non-string object that responds to to_s
.
Note that a resulted string should be used unquoted and is not intended for use in double quotes nor in single quotes.
argv = Shellwords.escape("It's better to give than to receive") argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
String#shellescape
is a shorthand for this function.
argv = "It's better to give than to receive".shellescape argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive" # Search files in lib for method definitions pattern = "^[ \t]*def " open("| grep -Ern -e #{pattern.shellescape} lib") { |grep| grep.each_line { |line| file, lineno, matched_line = line.split(':', 3) # ... } }
It is the caller’s responsibility to encode the string in the right encoding for the shell environment where this string is used.
Multibyte characters are treated as multibyte characters, not as bytes.
Returns an empty quoted String
if str
has a length of zero.
Escapes a string so that it can be safely used in a Bourne shell command line. str
can be a non-string object that responds to to_s
.
Note that a resulted string should be used unquoted and is not intended for use in double quotes nor in single quotes.
argv = Shellwords.escape("It's better to give than to receive") argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
String#shellescape
is a shorthand for this function.
argv = "It's better to give than to receive".shellescape argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive" # Search files in lib for method definitions pattern = "^[ \t]*def " open("| grep -Ern -e #{pattern.shellescape} lib") { |grep| grep.each_line { |line| file, lineno, matched_line = line.split(':', 3) # ... } }
It is the caller’s responsibility to encode the string in the right encoding for the shell environment where this string is used.
Multibyte characters are treated as multibyte characters, not as bytes.
Returns an empty quoted String
if str
has a length of zero.
Raises a TypeError
to prevent duping.
By default, do not retain any state when marshalling.
Serializes obj and all descendant objects. If anIO is specified, the serialized data will be written to it, otherwise the data will be returned as a String
. If limit is specified, the traversal of subobjects will be limited to that depth. If limit is negative, no checking of depth will be performed.
class Klass def initialize(str) @str = str end def say_hello @str end end
(produces no output)
o = Klass.new("hello\n") data = Marshal.dump(o) obj = Marshal.load(data) obj.say_hello #=> "hello\n"
Marshal
can’t dump following objects:
anonymous Class/Module.
objects which are related to system (ex: Dir
, File::Stat
, IO
, File
, Socket
and so on)
an instance of MatchData
, Data
, Method
, UnboundMethod
, Proc
, Thread
, ThreadGroup
, Continuation
objects which define singleton methods
Called after resolution ends (either successfully or with an error). By default, prints a newline.
@return [void]
Waits up to the continue timeout for a response from the server provided we’re speaking HTTP 1.1 and are expecting a 100-continue response.