Writes s in the non-blocking manner.
If there is buffered data, it is flushed first. This may block.
write_nonblock
returns number of bytes written to the SSL
connection.
When no data can be written without blocking it raises OpenSSL::SSL::SSLError
extended by IO::WaitReadable
or IO::WaitWritable
.
IO::WaitReadable
means SSL
needs to read internally so write_nonblock
should be called again after the underlying IO
is readable.
IO::WaitWritable
means SSL
needs to write internally so write_nonblock
should be called again after underlying IO
is writable.
So OpenSSL::Buffering#write_nonblock
needs two rescue clause as follows.
# emulates blocking write. begin result = ssl.write_nonblock(str) rescue IO::WaitReadable IO.select([io]) retry rescue IO::WaitWritable IO.select(nil, [io]) retry end
Note that one reason that write_nonblock
reads from the underlying IO
is when the peer requests a new TLS/SSL handshake. See the openssl FAQ for more details. www.openssl.org/support/faq.html
By specifying a keyword argument exception to false
, you can indicate that write_nonblock
should not raise an IO::Wait*able exception, but return the symbol :wait_writable
or :wait_readable
instead.
A utility method for encoding the String
s as a URL.
require "erb" include ERB::Util puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
Generates
Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
A utility method for encoding the String
s as a URL.
require "erb" include ERB::Util puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
Generates
Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
SecureRandom.urlsafe_base64 generates a random URL-safe base64 string.
The argument n specifies the length, in bytes, of the random number to be generated. The length of the result string is about 4/3 of n.
If n is not specified or is nil, 16 is assumed. It may be larger in the future.
The boolean argument padding specifies the padding. If it is false or nil, padding is not generated. Otherwise padding is generated. By default, padding is not generated because “=” may be used as a URL delimiter.
The result may contain A-Z, a-z, 0-9, “-” and “_”. “=” is also used if padding is true.
require 'securerandom' SecureRandom.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg" SecureRandom.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg" SecureRandom.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ==" SecureRandom.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
If a secure random number generator is not available, NotImplementedError
is raised.
See RFC 3548 for the definition of URL-safe base64.
Change the current process’s real and effective user ID to that specified by user. Returns the new user ID. Not available on all platforms.
[Process.uid, Process.euid] #=> [0, 0] Process::UID.change_privilege(31) #=> 31 [Process.uid, Process.euid] #=> [31, 31]
Set
the effective user ID, and if possible, the saved user ID of the process to the given user. Returns the new effective user ID. Not available on all platforms.
[Process.uid, Process.euid] #=> [0, 0] Process::UID.grant_privilege(31) #=> 31 [Process.uid, Process.euid] #=> [0, 31]
Change the current process’s real and effective group ID to that specified by group. Returns the new group ID. Not available on all platforms.
[Process.gid, Process.egid] #=> [0, 0] Process::GID.change_privilege(33) #=> 33 [Process.gid, Process.egid] #=> [33, 33]
Set
the effective group ID, and if possible, the saved group ID of the process to the given group. Returns the new effective group ID. Not available on all platforms.
[Process.gid, Process.egid] #=> [0, 0] Process::GID.grant_privilege(31) #=> 33 [Process.gid, Process.egid] #=> [0, 33]
Writes data
onto the IO
, raising a FileOverflow
exception if the number of bytes will be more than limit
Writes data
onto the IO
Returns the value of the given instance variable, or nil if the instance variable is not set. The @
part of the variable name should be included for regular instance variables. Throws a NameError
exception if the supplied symbol is not valid as an instance variable name. String
arguments are converted to symbols.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_get(:@a) #=> "cat" fred.instance_variable_get("@b") #=> 99
Sets the instance variable named by symbol to the given object. This may circumvent the encapsulation intended by the author of the class, so it should be used with care. The variable does not have to exist prior to this call. If the instance variable name is passed as a string, that string is converted to a symbol.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_set(:@a, 'dog') #=> "dog" fred.instance_variable_set(:@c, 'cat') #=> "cat" fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
Returns true
if the given instance variable is defined in obj. String
arguments are converted to symbols.
class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_defined?(:@a) #=> true fred.instance_variable_defined?("@b") #=> true fred.instance_variable_defined?("@c") #=> false
Removes the named instance variable from obj, returning that variable’s value. String
arguments are converted to symbols.
class Dummy attr_reader :var def initialize @var = 99 end def remove remove_instance_variable(:@var) end end d = Dummy.new d.var #=> 99 d.remove #=> 99 d.var #=> nil
Re-composes a prime factorization and returns the product.
See Prime#int_from_prime_division
for more details.
Returns a list of the private instance methods defined in mod. If the optional parameter is false
, the methods of any ancestors are not included.
module Mod def method1() end private :method1 def method2() end end Mod.instance_methods #=> [:method2] Mod.private_instance_methods #=> [:method1]
Returns the Ruby source filename and line number containing the definition of the constant specified. If the named constant is not found, nil
is returned. If the constant is found, but its source location can not be extracted (constant is defined in C code), empty array is returned.
inherit specifies whether to lookup in mod.ancestors
(true
by default).
# test.rb: class A # line 1 C1 = 1 C2 = 2 end module M # line 6 C3 = 3 end class B < A # line 10 include M C4 = 4 end class A # continuation of A definition C2 = 8 # constant redefinition; warned yet allowed end p B.const_source_location('C4') # => ["test.rb", 12] p B.const_source_location('C3') # => ["test.rb", 7] p B.const_source_location('C1') # => ["test.rb", 2] p B.const_source_location('C3', false) # => nil -- don't lookup in ancestors p A.const_source_location('C2') # => ["test.rb", 16] -- actual (last) definition place p Object.const_source_location('B') # => ["test.rb", 10] -- top-level constant could be looked through Object p Object.const_source_location('A') # => ["test.rb", 1] -- class reopening is NOT considered new definition p B.const_source_location('A') # => ["test.rb", 1] -- because Object is in ancestors p M.const_source_location('A') # => ["test.rb", 1] -- Object is not ancestor, but additionally checked for modules p Object.const_source_location('A::C1') # => ["test.rb", 2] -- nesting is supported p Object.const_source_location('String') # => [] -- constant is defined in C code
Removes the named class variable from the receiver, returning that variable’s value.
class Example @@var = 99 puts remove_class_variable(:@@var) p(defined? @@var) end
produces:
99 nil
Returns the value of the given class variable (or throws a NameError
exception). The @@
part of the variable name should be included for regular class variables. String
arguments are converted to symbols.
class Fred @@foo = 99 end Fred.class_variable_get(:@@foo) #=> 99
Sets the class variable named by symbol to the given object. If the class variable name is passed as a string, that string is converted to a symbol.
class Fred @@foo = 99 def foo @@foo end end Fred.class_variable_set(:@@foo, 101) #=> 101 Fred.new.foo #=> 101
Returns true
if the given class variable is defined in obj. String
arguments are converted to symbols.
class Fred @@foo = 99 end Fred.class_variable_defined?(:@@foo) #=> true Fred.class_variable_defined?(:@@bar) #=> false
Returns true
if the named private method is defined by mod. If inherit is set, the lookup will also search mod’s ancestors. String
arguments are converted to symbols.
module A def method1() end end class B private def method2() end end class C < B include A def method3() end end A.method_defined? :method1 #=> true C.private_method_defined? "method1" #=> false C.private_method_defined? "method2" #=> true C.private_method_defined? "method2", true #=> true C.private_method_defined? "method2", false #=> false C.method_defined? "method2" #=> false