instance_exec

obj.instance_exec(arg...) {|var...| block } â obj Instance Public methods Executes the given block within the context of the receiver (obj). In order to set the context, the variable self is set to obj while the code is executing, giving the code access to obj's instance variables. Arguments are passed as block parameters. class KlassWithSecret def initialize @secret = 99 end end k = KlassWithSecret.new k.instance_exec(5) {|x| @secret+x } #=> 10

do_not_reverse_lookup

BasicSocket.do_not_reverse_lookup => true or false Class Public methods Gets the global ::do_not_reverse_lookup flag. BasicSocket.do_not_reverse_lookup #=> false

do_not_reverse_lookup=

BasicSocket.do_not_reverse_lookup = bool Class Public methods Sets the global ::do_not_reverse_lookup flag. The flag is used for initial value of ::do_not_reverse_lookup for each socket. s1 = TCPSocket.new("localhost", 80) p s1.do_not_reverse_lookup #=> true BasicSocket.do_not_reverse_lookup = false s2 = TCPSocket.new("localhost", 80) p s2.do_not_reverse_lookup #=> false p s1.do_not_reverse_lookup #=> true

for_fd

BasicSocket.for_fd(fd) => basicsocket Class Public methods Returns a socket object which contains the file descriptor, fd. # If invoked by inetd, STDIN/STDOUT/STDERR is a socket. STDIN_SOCK = Socket.for_fd(STDIN.fileno) p STDIN_SOCK.remote_address

close_read

basicsocket.close_read => nil Instance Public methods Disallows further read using shutdown system call. s1, s2 = UNIXSocket.pair s1.close_read s2.puts #=> Broken pipe (Errno::EPIPE)

close_write

basicsocket.close_write => nil Instance Public methods Disallows further write using shutdown system call. UNIXSocket.pair {|s1, s2| s1.print "ping" s1.close_write p s2.read #=> "ping" s2.print "pong" s2.close p s1.read #=> "pong" }

connect_address

connect_address() Instance Public methods Returns an address of the socket suitable for connect in the local machine. This method returns self.local_address, except following condition. IPv4 unspecified address (0.0.0.0) is replaced by IPv4 loopback address (127.0.0.1). IPv6 unspecified address (::) is replaced by IPv6 loopback address (::1). If the local address is not suitable for connect, SocketError is raised. IPv4 and IPv6 address which port is 0 is not suitable for conn

do_not_reverse_lookup 2

basicsocket.do_not_reverse_lookup => true or false Instance Public methods Gets the ::do_not_reverse_lookup flag of basicsocket. TCPSocket.open("www.ruby-lang.org", 80) {|sock| p sock.do_not_reverse_lookup #=> false p sock.peeraddr #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"] sock.do_not_reverse_lookup = true p sock.peeraddr #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"] }

do_not_reverse_lookup= 2

basicsocket.do_not_reverse_lookup = bool Instance Public methods Sets the ::do_not_reverse_lookup flag of basicsocket. BasicSocket.do_not_reverse_lookup = false p TCPSocket.new("127.0.0.1", 80).do_not_reverse_lookup #=> false BasicSocket.do_not_reverse_lookup = true p TCPSocket.new("127.0.0.1", 80).do_not_reverse_lookup #=> true

getpeereid

basicsocket.getpeereid => [euid, egid] Instance Public methods 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 }