Returns the number of key-value pairs in this database.
Adds the key-value pairs of other to gdbm, overwriting entries with duplicate keys with those from other. other must have an each_pair
method.
Returns true if the given key k exists within the database. Returns false otherwise.
Returns true
if obj
is an element of the range, false
otherwise.
("a".."z").include?("g") #=> true ("a".."z").include?("A") #=> false ("a".."z").include?("cc") #=> false
If you need to ensure obj
is between begin
and end
, use cover?
("a".."z").cover?("cc") #=> true
If begin and end are numeric, include?
behaves like cover?
(1..3).include?(1.5) # => true
Returns a MatchData
object describing the match, or nil
if there was no match. This is equivalent to retrieving the value of the special variable $~
following a normal match. If the second parameter is present, it specifies the position in the string to begin the search.
/(.)(.)(.)/.match("abc")[2] #=> "b" /(.)(.)/.match("abc", 1)[2] #=> "c"
If a block is given, invoke the block with MatchData
if match succeed, so that you can write
/M(.*)/.match("Matz") do |m| puts m[0] puts m[1] end
instead of
if m = /M(.*)/.match("Matz") puts m[0] puts m[1] end
The return value is a value from block execution in this case.
Returns a true
or false
indicates whether the regexp is matched or not without updating $~ and other related variables. If the second parameter is present, it specifies the position in the string to begin the search.
/R.../.match?("Ruby") #=> true /R.../.match?("Ruby", 1) #=> false /P.../.match?("Ruby") #=> false $& #=> nil
Returns a new set that is a copy of the set, flattening each containing set recursively.
Equivalent to Set#flatten
, but replaces the receiver with the result in place. Returns nil if no modifications were made.
Merges the elements of the given enumerable object to the set and returns self.
Same as sym.to_s.length
.
Returns sym.to_s.match
.
Returns sym.to_s.match?
.
Allocates space for a new object of class’s class and does not call initialize on the new instance. The returned object must be an instance of class.
klass = Class.new do def initialize(*args) @initialized = true end def initialized? @initialized || false end end klass.allocate.initialized? #=> false
Parses the given Ruby program read from src
. src
must be a String
or an IO
or a object with a gets
method.
Start parsing and returns the value of the root action.
Return scanner state of current token.
Returns the number of keys in the database.
Insert or update key-value pairs.
This method will work with any object which implements an each_pair
method, such as a Hash
.
Returns true
if the database contains the given key
.
Creates a pair of sockets connected each other.
domain should be a communications domain such as: :INET, :INET6, :UNIX, etc.
socktype should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
protocol should be a protocol defined in the domain, defaults to 0 for the domain.
s1, s2 = Socket.pair(:UNIX, :STREAM, 0) s1.send "a", 0 s1.send "b", 0 s1.close p s2.recv(10) #=> "ab" p s2.recv(10) #=> "" p s2.recv(10) #=> "" s1, s2 = Socket.pair(:UNIX, :DGRAM, 0) s1.send "a", 0 s1.send "b", 0 p s2.recv(10) #=> "a" p s2.recv(10) #=> "b"
Creates a pair of sockets connected each other.
domain should be a communications domain such as: :INET, :INET6, :UNIX, etc.
socktype should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.
protocol should be a protocol defined in the domain, defaults to 0 for the domain.
s1, s2 = Socket.pair(:UNIX, :STREAM, 0) s1.send "a", 0 s1.send "b", 0 s1.close p s2.recv(10) #=> "ab" p s2.recv(10) #=> "" p s2.recv(10) #=> "" s1, s2 = Socket.pair(:UNIX, :DGRAM, 0) s1.send "a", 0 s1.send "b", 0 p s2.recv(10) #=> "a" p s2.recv(10) #=> "b"
Use Addrinfo#getnameinfo
instead. This method is deprecated for the following reasons:
Uncommon address representation: 4/16-bytes binary string to represent IPv4/IPv6 address.
gethostbyaddr() may take a long time and it may block other threads. (GVL cannot be released since gethostbyname() is not thread safe.)
This method uses gethostbyname() function already removed from POSIX.
This method obtains the host information for address.
p Socket.gethostbyaddr([221,186,184,68].pack("CCCC")) #=> ["carbon.ruby-lang.org", [], 2, "\xDD\xBA\xB8D"] p Socket.gethostbyaddr([127,0,0,1].pack("CCCC")) ["localhost", [], 2, "\x7F\x00\x00\x01"] p Socket.gethostbyaddr(([0]*15+[1]).pack("C"*16)) #=> ["localhost", ["ip6-localhost", "ip6-loopback"], 10, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"]
returns the address family as an integer.
Addrinfo.tcp("localhost", 80).afamily == Socket::AF_INET #=> true