Mirror the Prism.dump
API by using the serialization API.
Mirror the Prism.lex
API by using the serialization API.
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
Returns the Object#object_id
of the internal object.
Extracts addr from IPV6_PKTINFO ancillary data.
IPV6_PKTINFO is defined by RFC 3542.
addr = Addrinfo.ip("::1") ifindex = 0 ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) p ancdata.ipv6_pktinfo_addr #=> #<Addrinfo: ::1>
Extracts ifindex from IPV6_PKTINFO ancillary data.
IPV6_PKTINFO is defined by RFC 3542.
addr = Addrinfo.ip("::1") ifindex = 0 ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) p ancdata.ipv6_pktinfo_ifindex #=> 0
def contains_keyword_splat?: () -> bool
The character offset from the beginning of the source where this location starts.
The character offset from the beginning of the source where this location ends.
The column number in characters where this location ends from the start of the line.
The column number in characters where this location ends from the start of the line.