Returns a string representation of self
, formatted by strftime('%a %b %e %T %Y')
or its shorthand version strftime('%c')
; see Formats for Dates and Times:
t = Time.new(2000, 12, 31, 23, 59, 59, 0.5) t.ctime # => "Sun Dec 31 23:59:59 2000" t.strftime('%a %b %e %T %Y') # => "Sun Dec 31 23:59:59 2000" t.strftime('%c') # => "Sun Dec 31 23:59:59 2000"
Related: Time#to_s
, Time#inspect
:
t.inspect # => "2000-12-31 23:59:59.5 +000001" t.to_s # => "2000-12-31 23:59:59 +0000"
Returns a string representation of self
, formatted by strftime('%a %b %e %T %Y')
or its shorthand version strftime('%c')
; see Formats for Dates and Times:
t = Time.new(2000, 12, 31, 23, 59, 59, 0.5) t.ctime # => "Sun Dec 31 23:59:59 2000" t.strftime('%a %b %e %T %Y') # => "Sun Dec 31 23:59:59 2000" t.strftime('%c') # => "Sun Dec 31 23:59:59 2000"
Related: Time#to_s
, Time#inspect
:
t.inspect # => "2000-12-31 23:59:59.5 +000001" t.to_s # => "2000-12-31 23:59:59 +0000"
Invokes Posix system call ioctl(2), which issues a low-level command to an I/O device.
Issues a low-level command to an I/O device. The arguments and returned value are platform-dependent. The effect of the call is platform-dependent.
If argument argument
is an integer, it is passed directly; if it is a string, it is interpreted as a binary sequence of bytes.
Not implemented on all platforms.
Returns rat
truncated (toward zero) to a precision of ndigits
decimal digits (default: 0).
When the precision is negative, the returned value is an integer with at least ndigits.abs
trailing zeros.
Returns a rational when ndigits
is positive, otherwise returns an integer.
Rational(3).truncate #=> 3 Rational(2, 3).truncate #=> 0 Rational(-3, 2).truncate #=> -1 # decimal - 1 2 3 . 4 5 6 # ^ ^ ^ ^ ^ ^ # precision -3 -2 -1 0 +1 +2 Rational('-123.456').truncate(+1).to_f #=> -123.4 Rational('-123.456').truncate(-1) #=> -120
Returns the values in self
as an array:
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.to_a # => ["Joe Smith", "123 Maple, Anytown NC", 12345]
Related: members
.
Returns the last change time, using directory information, not the file itself.
See File.ctime
.
Requests a connection to be made on the given remote_sockaddr
. Returns 0 if successful, otherwise an exception is raised.
remote_sockaddr
- the struct
sockaddr contained in a string or Addrinfo
object
# Pull down Google's web page require 'socket' include Socket::Constants socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) sockaddr = Socket.pack_sockaddr_in( 80, 'www.google.com' ) socket.connect( sockaddr ) socket.write( "GET / HTTP/1.0\r\n\r\n" ) results = socket.read
On unix-based systems the following system exceptions may be raised if the call to connect fails:
Errno::EACCES - search permission is denied for a component of the prefix path or write access to the socket
is denied
Errno::EADDRINUSE - the sockaddr is already in use
Errno::EADDRNOTAVAIL - the specified sockaddr is not available from the local machine
Errno::EAFNOSUPPORT - the specified sockaddr is not a valid address for the address family of the specified socket
Errno::EALREADY - a connection is already in progress for the specified socket
Errno::EBADF - the socket
is not a valid file descriptor
Errno::ECONNREFUSED - the target sockaddr was not listening for connections refused the connection request
Errno::ECONNRESET - the remote host reset the connection request
Errno::EFAULT - the sockaddr cannot be accessed
Errno::EHOSTUNREACH - the destination host cannot be reached (probably because the host is down or a remote router cannot reach it)
Errno::EINPROGRESS - the O_NONBLOCK is set for the socket
and the connection cannot be immediately established; the connection will be established asynchronously
Errno::EINTR - the attempt to establish the connection was interrupted by delivery of a signal that was caught; the connection will be established asynchronously
Errno::EISCONN - the specified socket
is already connected
Errno::EINVAL - the address length used for the sockaddr is not a valid length for the address family or there is an invalid family in sockaddr
Errno::ENAMETOOLONG - the pathname resolved had a length which exceeded PATH_MAX
Errno::ENETDOWN - the local interface used to reach the destination is down
Errno::ENETUNREACH - no route to the network is present
Errno::ENOBUFS - no buffer space is available
Errno::ENOSR - there were insufficient STREAMS resources available to complete the operation
Errno::ENOTSOCK - the socket
argument does not refer to a socket
Errno::EOPNOTSUPP - the calling socket
is listening and cannot be connected
Errno::EPROTOTYPE - the sockaddr has a different type than the socket bound to the specified peer address
Errno::ETIMEDOUT - the attempt to connect timed out before a connection was made.
On unix-based systems if the address family of the calling socket
is AF_UNIX
the follow exceptions may be raised if the call to connect fails:
Errno::EIO - an i/o error occurred while reading from or writing to the file system
Errno::ELOOP - too many symbolic links were encountered in translating the pathname in sockaddr
Errno::ENAMETOOLLONG - a component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX characters
Errno::ENOENT - a component of the pathname does not name an existing file or the pathname is an empty string
Errno::ENOTDIR - a component of the path prefix of the pathname in sockaddr is not a directory
On Windows systems the following system exceptions may be raised if the call to connect fails:
Errno::ENETDOWN - the network is down
Errno::EADDRINUSE - the socket’s local address is already in use
Errno::EINTR - the socket was cancelled
Errno::EINPROGRESS - a blocking socket is in progress or the service provider is still processing a callback function. Or a nonblocking connect call is in progress on the socket
.
Errno::EALREADY - see Errno::EINVAL
Errno::EADDRNOTAVAIL - the remote address is not a valid address, such as ADDR_ANY TODO check ADDRANY TO INADDR_ANY
Errno::EAFNOSUPPORT - addresses in the specified family cannot be used with with this socket
Errno::ECONNREFUSED - the target sockaddr was not listening for connections refused the connection request
Errno::EFAULT - the socket’s internal address or address length parameter is too small or is not a valid part of the user space address
Errno::EINVAL - the socket
is a listening socket
Errno::EISCONN - the socket
is already connected
Errno::ENETUNREACH - the network cannot be reached from this host at this time
Errno::EHOSTUNREACH - no route to the network is present
Errno::ENOBUFS - no buffer space is available
Errno::ENOTSOCK - the socket
argument does not refer to a socket
Errno::ETIMEDOUT - the attempt to connect timed out before a connection was made.
Errno::EWOULDBLOCK - the socket is marked as nonblocking and the connection cannot be completed immediately
Errno::EACCES - the attempt to connect the datagram socket to the broadcast address failed
connect manual pages on unix-based systems
connect function in Microsoft’s Winsock functions reference
creates a socket connected to the address of self.
The optional argument opts is options represented by a hash. opts may have following options:
specify the timeout in seconds.
If a block is given, it is called with the socket and the value of the block is returned. The socket is returned otherwise.
Addrinfo.tcp("www.ruby-lang.org", 80).connect {|s| s.print "GET / HTTP/1.0\r\nHost: www.ruby-lang.org\r\n\r\n" puts s.read }
Connects udpsocket to host:port.
This makes possible to send without destination address.
u1 = UDPSocket.new u1.bind("127.0.0.1", 4913) u2 = UDPSocket.new u2.connect("127.0.0.1", 4913) u2.send "uuuu", 0 p u1.recvfrom(10) #=> ["uuuu", ["AF_INET", 33230, "localhost", "127.0.0.1"]]
Truncates the buffer string to at most integer bytes. The stream must be opened for writing.
Appends str
to the string being scanned. This method does not affect scan pointer.
s = StringScanner.new("Fri Dec 12 1975 14:39") s.scan(/Fri /) s << " +1000 GMT" s.string # -> "Fri Dec 12 1975 14:39 +1000 GMT" s.scan(/Dec/) # -> "Dec"
Returns running OLE Automation object or WIN32OLE
object from moniker. 1st argument should be OLE program id or class id or moniker.
WIN32OLE.connect('Excel.Application') # => WIN32OLE object which represents running Excel.
Returns revision information for the erb.rb module.
Returns the values in self
as an array, to use in pattern matching:
Measure = Data.define(:amount, :unit) distance = Measure[10, 'km'] distance.deconstruct #=> [10, "km"] # usage case distance in n, 'km' # calls #deconstruct underneath puts "It is #{n} kilometers away" else puts "Don't know how to handle it" end # prints "It is 10 kilometers away"
Or, with checking the class, too:
case distance in Measure(n, 'km') puts "It is #{n} kilometers away" # ... end
Returns the array of captures, which are all matches except m[0]
:
m = /(.)(.)(\d+)(\d)/.match("THX1138.") # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8"> m[0] # => "HX1138" m.captures # => ["H", "X", "113", "8"]
Related: MatchData.to_a
.
Establishes proc on thr as the handler for tracing, or disables tracing if the parameter is nil
.
Adds proc as a handler for tracing.
Establishes proc as the handler for tracing, or disables tracing if the parameter is nil
.
Note: this method is obsolete, please use TracePoint
instead.
proc takes up to six parameters:
an event name string
a filename string
a line number
a method name symbol, or nil
a binding, or nil
the class, module, or nil
proc is invoked whenever an event occurs.
Events are:
"c-call"
call a C-language routine
"c-return"
return from a C-language routine
"call"
call a Ruby method
"class"
start a class or module definition
"end"
finish a class or module definition
"line"
execute code on a new line
"raise"
raise an exception
"return"
return from a Ruby method
Tracing is disabled within the context of proc.
class Test def test a = 1 b = 2 end end set_trace_func proc { |event, file, line, id, binding, class_or_module| printf "%8s %s:%-2d %16p %14p\n", event, file, line, id, class_or_module } t = Test.new t.test
Produces:
c-return prog.rb:8 :set_trace_func Kernel line prog.rb:11 nil nil c-call prog.rb:11 :new Class c-call prog.rb:11 :initialize BasicObject c-return prog.rb:11 :initialize BasicObject c-return prog.rb:11 :new Class line prog.rb:12 nil nil call prog.rb:2 :test Test line prog.rb:3 :test Test line prog.rb:4 :test Test return prog.rb:5 :test Test
Returns the class for the given object
.
class A def foo ObjectSpace::trace_object_allocations do obj = Object.new p "#{ObjectSpace::allocation_class_path(obj)}" end end end A.new.foo #=> "Class"
See ::trace_object_allocations
for more information and examples.