Returns the short user name of the currently logged in user. Unfortunately, it is often rather easy to fool ::getlogin
.
Avoid ::getlogin
for security-related purposes.
If ::getlogin
fails, try ::getpwuid
.
See the unix manpage for getpwuid(3)
for more detail.
e.g.
Etc.getlogin -> 'guest'
Returns the current list of converters in effect for headers. See CSV::new
for details. Built-in converters will be returned by name, while others will be returned as is.
Returns garbage collector generation for the given object
.
class B include ObjectSpace def foo trace_object_allocations do obj = Object.new p "Generation is #{allocation_generation(obj)}" end end end B.new.foo #=> "Generation is 3"
See ::trace_object_allocations
for more information and examples.
debugging output for msg
The server hostname
The server hostname
Since int
is already an Integer
, this always returns true
.
Returns a new Time
object representing time in local time (using the local time zone in effect for this process).
If utc_offset
is given, it is used instead of the local time. utc_offset
can be given as a human-readable string (eg. "+09:00"
) or as a number of seconds (eg. 32400
).
t = Time.utc(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC t.utc? #=> true l = t.getlocal #=> 2000-01-01 14:15:01 -0600 l.utc? #=> false t == l #=> true j = t.getlocal("+09:00") #=> 2000-01-02 05:15:01 +0900 j.utc? #=> false t == j #=> true k = t.getlocal(9*60*60) #=> 2000-01-02 05:15:01 +0900 k.utc? #=> false t == k #=> true
Obtains the port number for service_name.
If protocol_name is not given, “tcp” is assumed.
Socket.getservbyname("smtp") #=> 25 Socket.getservbyname("shell") #=> 514 Socket.getservbyname("syslog", "udp") #=> 514
Obtains the port number for port.
If protocol_name is not given, “tcp” is assumed.
Socket.getservbyport(80) #=> "www" Socket.getservbyport(514, "tcp") #=> "shell" Socket.getservbyport(514, "udp") #=> "syslog"
Returns the remote address of the socket as a sockaddr string.
TCPServer.open("127.0.0.1", 1440) {|serv| c = TCPSocket.new("127.0.0.1", 1440) s = serv.accept p s.getpeername #=> "\x02\x00\x82u\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00" }
If Addrinfo
object is preferred over the binary string, use BasicSocket#remote_address
.
Returns the user and group on the peer of the UNIX socket. The result is a two element array which contains the effective uid and the effective gid.
Socket.unix_server_loop("/tmp/sock") {|s| begin euid, egid = s.getpeereid # Check the connected client is myself or not. next if euid != Process.uid # do something about my resource. ensure s.close end }
Runs the early binding method to get property. The 1st argument specifies dispatch ID, the 2nd argument specifies the array of arguments, the 3rd argument specifies the array of the type of arguments.
excel = WIN32OLE.new('Excel.Application') puts excel._getproperty(558, [], []) # same effect as puts excel.visible
Adds the contents of other_hash to hsh. If no block is specified, entries with duplicate keys are overwritten with the values from other_hash, otherwise the value of each duplicate key is determined by calling the block with the key, its value in hsh and its value in other_hash.
h1 = { "a" => 100, "b" => 200 } h2 = { "b" => 254, "c" => 300 } h1.merge!(h2) #=> {"a"=>100, "b"=>254, "c"=>300} h1 #=> {"a"=>100, "b"=>254, "c"=>300} h1 = { "a" => 100, "b" => 200 } h2 = { "b" => 254, "c" => 300 } h1.merge!(h2) { |key, v1, v2| v1 } #=> {"a"=>100, "b"=>200, "c"=>300} h1 #=> {"a"=>100, "b"=>200, "c"=>300}
Returns a new hash containing the contents of other_hash and the contents of hsh. If no block is specified, the value for entries with duplicate keys will be that of other_hash. Otherwise the value for each duplicate key is determined by calling the block with the key, its value in hsh and its value in other_hash.
h1 = { "a" => 100, "b" => 200 } h2 = { "b" => 254, "c" => 300 } h1.merge(h2) #=> {"a"=>100, "b"=>254, "c"=>300} h1.merge(h2){|key, oldval, newval| newval - oldval} #=> {"a"=>100, "b"=>54, "c"=>300} h1 #=> {"a"=>100, "b"=>200}
This method wraps a String you provide, or an empty default String, in a CSV
object which is passed to the provided block. You can use the block to append CSV
rows to the String and when the block exits, the final String will be returned.
Note that a passed String is modified by this method. Call dup() before passing if you need a new String.
The options
parameter can be anything CSV::new()
understands. This method understands an additional :encoding
parameter when not passed a String to set the base Encoding
for the output. CSV
needs this hint if you plan to output non-ASCII compatible data.
Returns the current list of converters in effect. See CSV::new
for details. Built-in converters will be returned by name, while others will be returned as is.