Sets auto-close flag.
f = open("/dev/null") IO.for_fd(f.fileno) # ... f.gets # may cause IOError f = open("/dev/null") IO.for_fd(f.fileno).autoclose = true # ... f.gets # won't cause IOError
Closes the associated database file.
Returns true if the associated database file has been closed.
Returns a hash created by using gdbm’s values as keys, and the keys as values.
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. If begin and end are numeric, comparison is done according to the magnitude of the values.
("a".."z").include?("g") #=> true ("a".."z").include?("A") #=> false ("a".."z").include?("cc") #=> false
Returns true
if obj
is between the begin and end of the range.
This tests begin <= obj <= end
when exclude_end?
is false
and begin <= obj < end
when exclude_end?
is true
.
("a".."z").cover?("c") #=> true ("a".."z").cover?("5") #=> false ("a".."z").cover?("cc") #=> true
provides a unified clone
operation, for REXML::XPathParser
to use across multiple Object
types
In general, to_sym
returns the Symbol
corresponding to an object. As sym is already a symbol, self
is returned in this case.
Callback invoked whenever a subclass of the current class is created.
Example:
class Foo def self.inherited(subclass) puts "New subclass: #{subclass}" end end class Bar < Foo end class Baz < Bar end
produces:
New subclass: Bar New subclass: Baz
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
Returns the superclass of class, or nil
.
File.superclass #=> IO IO.superclass #=> Object Object.superclass #=> BasicObject class Foo; end class Bar < Foo; end Bar.superclass #=> Foo
Returns nil when the given class does not have a parent class:
BasicObject.superclass #=> nil
Returns or yields Pathname
objects.
Pathname.glob("config/" "*.rb") #=> [#<Pathname:config/environment.rb>, #<Pathname:config/routes.rb>, ..]
See Dir.glob
.
Returns the current working directory as a Pathname
.
Pathname.getwd #=> #<Pathname:/home/zzak/projects/ruby>
See Dir.getwd
.
Return true if parsed source has errors.
Returns true
if the database is closed.
Returns a Hash
in which the key-value pairs have been inverted.
Example:
require 'sdbm' SDBM.open 'my_database' do |db| db.update('apple' => 'fruit', 'spinach' => 'vegetable') db.invert #=> {"fruit" => "apple", "vegetable" => "spinach"} end
Returns true
if the database contains the given key
.
Returns an array of interface addresses. An element of the array is an instance of Socket::Ifaddr
.
This method can be used to find multicast-enabled interfaces:
pp Socket.getifaddrs.reject {|ifaddr| !ifaddr.addr.ip? || (ifaddr.flags & Socket::IFF_MULTICAST == 0) }.map {|ifaddr| [ifaddr.name, ifaddr.ifindex, ifaddr.addr] } #=> [["eth0", 2, #<Addrinfo: 221.186.184.67>], # ["eth0", 2, #<Addrinfo: fe80::216:3eff:fe95:88bb%eth0>]]
Example result on GNU/Linux:
pp Socket.getifaddrs #=> [#<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 PACKET[protocol=0 lo hatype=772 HOST hwaddr=00:00:00:00:00:00]>, # #<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 PACKET[protocol=0 eth0 hatype=1 HOST hwaddr=00:16:3e:95:88:bb] broadcast=PACKET[protocol=0 eth0 hatype=1 HOST hwaddr=ff:ff:ff:ff:ff:ff]>, # #<Socket::Ifaddr sit0 NOARP PACKET[protocol=0 sit0 hatype=776 HOST hwaddr=00:00:00:00]>, # #<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 127.0.0.1 netmask=255.0.0.0>, # #<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 221.186.184.67 netmask=255.255.255.240 broadcast=221.186.184.79>, # #<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 ::1 netmask=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>, # #<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 fe80::216:3eff:fe95:88bb%eth0 netmask=ffff:ffff:ffff:ffff::>]
Example result on FreeBSD:
pp Socket.getifaddrs #=> [#<Socket::Ifaddr usbus0 UP,0x10000 LINK[usbus0]>, # #<Socket::Ifaddr re0 UP,BROADCAST,RUNNING,MULTICAST,0x800 LINK[re0 3a:d0:40:9a:fe:e8]>, # #<Socket::Ifaddr re0 UP,BROADCAST,RUNNING,MULTICAST,0x800 10.250.10.18 netmask=255.255.255.? (7 bytes for 16 bytes sockaddr_in) broadcast=10.250.10.255>, # #<Socket::Ifaddr re0 UP,BROADCAST,RUNNING,MULTICAST,0x800 fe80:2::38d0:40ff:fe9a:fee8 netmask=ffff:ffff:ffff:ffff::>, # #<Socket::Ifaddr re0 UP,BROADCAST,RUNNING,MULTICAST,0x800 2001:2e8:408:10::12 netmask=UNSPEC>, # #<Socket::Ifaddr plip0 POINTOPOINT,MULTICAST,0x800 LINK[plip0]>, # #<Socket::Ifaddr lo0 UP,LOOPBACK,RUNNING,MULTICAST LINK[lo0]>, # #<Socket::Ifaddr lo0 UP,LOOPBACK,RUNNING,MULTICAST ::1 netmask=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>, # #<Socket::Ifaddr lo0 UP,LOOPBACK,RUNNING,MULTICAST fe80:4::1 netmask=ffff:ffff:ffff:ffff::>, # #<Socket::Ifaddr lo0 UP,LOOPBACK,RUNNING,MULTICAST 127.0.0.1 netmask=255.?.?.? (5 bytes for 16 bytes sockaddr_in)>]
Returns the hostname.
p Socket.gethostname #=> "hal"
Note that it is not guaranteed to be able to convert to IP address using gethostbyname, getaddrinfo, etc. If you need local IP address, use Socket.ip_address_list
.
Obtains the host information for hostname.
p Socket.gethostbyname("hal") #=> ["localhost", ["hal"], 2, "\x7F\x00\x00\x01"]
Obtains the host information for address.
p Socket.gethostbyaddr([221,186,184,68].pack("CCCC")) #=> ["carbon.ruby-lang.org", [], 2, "\xDD\xBA\xB8D"]