Returns the maximum size of the queue.
Sets the maximum size of the queue to the given number
.
Returns the conversion path of ec.
The result is an array of conversions.
ec = Encoding::Converter.new("ISO-8859-1", "EUC-JP", crlf_newline: true) p ec.convpath #=> [[#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>], # [#<Encoding:UTF-8>, #<Encoding:EUC-JP>], # "crlf_newline"]
Each element of the array is a pair of encodings or a string. A pair means an encoding conversion. A string means a decorator.
In the above example, [#<Encoding:ISO-8859-1>,
Iterates over keys and values. Note that unlike other collections, each
without block isn’t supported.
Updates the digest using a given string and returns self.
The update() method and the left-shift operator are overridden by each implementation subclass. (One should be an alias for the other)
Construct a new class given a C:
class klass
(CUnion
, CStruct
, or other that provide an entity_class)
types
(Fiddle::TYPE_INT, Fiddle::TYPE_SIZE_T, etc., see the C types constants)
corresponding members
Fiddle::Importer#struct
and Fiddle::Importer#union
wrap this functionality in an easy-to-use manner.
Examples:
require 'fiddle/struct' require 'fiddle/cparser' include Fiddle::CParser types, members = parse_struct_signature(['int i','char c']) MyStruct = Fiddle::CStructBuilder.create(Fiddle::CUnion, types, members) MyStruct.malloc(Fiddle::RUBY_FREE) do |obj| ... end obj = MyStruct.malloc(Fiddle::RUBY_FREE) begin ... ensure obj.call_free end obj = MyStruct.malloc begin ... ensure Fiddle.free obj.to_ptr end
Construct a new class given a C:
class klass
(CUnion
, CStruct
, or other that provide an entity_class)
types
(Fiddle::TYPE_INT, Fiddle::TYPE_SIZE_T, etc., see the C types constants)
corresponding members
Fiddle::Importer#struct
and Fiddle::Importer#union
wrap this functionality in an easy-to-use manner.
Examples:
require 'fiddle/struct' require 'fiddle/cparser' include Fiddle::CParser types, members = parse_struct_signature(['int i','char c']) MyStruct = Fiddle::CStructBuilder.create(Fiddle::CUnion, types, members) MyStruct.malloc(Fiddle::RUBY_FREE) do |obj| ... end obj = MyStruct.malloc(Fiddle::RUBY_FREE) begin ... ensure obj.call_free end obj = MyStruct.malloc begin ... ensure Fiddle.free obj.to_ptr end
Executes the block for every line in the stream where lines are separated by eol.
See also gets
Reads one character from the stream. Returns nil if called at end of file.
Reads a one-character string from the stream. Raises an EOFError
at end of file.
Pushes character c back onto the stream such that a subsequent buffered character read will return it.
Unlike IO#getc
multiple bytes may be pushed back onto the stream.
Has no effect on unbuffered reads (such as sysread).
Return true
if the PRNG has been seeded with enough data, false
otherwise.
Generate a Checkbox Input element as a string.
The attributes of the element can be specified as three arguments, name
, value
, and checked
. checked
is a boolean value; if true, the CHECKED attribute will be included in the element.
Alternatively, the attributes can be specified as a hash.
checkbox("name") # = checkbox("NAME" => "name") checkbox("name", "value") # = checkbox("NAME" => "name", "VALUE" => "value") checkbox("name", "value", true) # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
Returns true
if field 'Transfer-Encoding'
exists and has value 'chunked'
, false
otherwise; see Transfer-Encoding response header:
res = Net::HTTP.get_response(hostname, '/todos/1') res['Transfer-Encoding'] # => "chunked" res.chunked? # => true
returns a charset parameter in Content-Type field. It is downcased for canonicalization.
If charset parameter is not given but a block is given, the block is called and its result is returned. It can be used to guess charset.
If charset parameter and block is not given, nil is returned except text type. In that case, “utf-8” is returned as defined by RFC6838 4.2.1
Generate a string that randomly draws from a source array of characters.
The argument source specifies the array of characters from which to generate the string. The argument n specifies the length, in characters, of the string to be generated.
The result may contain whatever characters are in the source array.
require 'random/formatter' prng.choose([*'l'..'r'], 16) #=> "lmrqpoonmmlqlron" prng.choose([*'0'..'9'], 5) #=> "27309"
Simple deprecation method that deprecates name
by wrapping it up in a dummy method. It warns on each call to the dummy method telling the user of repl
(unless repl
is :none) and the year/month that it is planned to go away.
A Zlib::Inflate#inflate
wrapper
Iterates over array indexes.
When a block given, passes each successive array index to the block; returns self
:
a = [:foo, 'bar', 2] a.each_index {|index| puts "#{index} #{a[index]}" }
Output:
0 foo 1 bar 2 2
Allows the array to be modified during iteration:
a = [:foo, 'bar', 2] a.each_index {|index| puts index; a.clear if index > 0 }
Output:
0 1
When no block given, returns a new Enumerator:
a = [:foo, 'bar', 2] e = a.each_index e # => #<Enumerator: [:foo, "bar", 2]:each_index> a1 = e.each {|index| puts "#{index} #{a[index]}"}
Output:
0 foo 1 bar 2 2
Related: each
, reverse_each
.
Iterates backwards over array elements.
When a block given, passes, in reverse order, each element to the block; returns self
:
a = [:foo, 'bar', 2] a.reverse_each {|element| puts "#{element.class} #{element}" }
Output:
Integer 2 String bar Symbol foo
Allows the array to be modified during iteration:
a = [:foo, 'bar', 2] a.reverse_each {|element| puts element; a.clear if element.to_s.start_with?('b') }
Output:
2 bar
When no block given, returns a new Enumerator:
a = [:foo, 'bar', 2] e = a.reverse_each e # => #<Enumerator: [:foo, "bar", 2]:reverse_each> a1 = e.each {|element| puts "#{element.class} #{element}" }
Output:
Integer 2 String bar Symbol foo
Related: each
, each_index
.
Returns a new Array
whose elements are the elements of self
at the given Integer
or Range
indexes
.
For each positive index
, returns the element at offset index
:
a = [:foo, 'bar', 2] a.values_at(0, 2) # => [:foo, 2] a.values_at(0..1) # => [:foo, "bar"]
The given indexes
may be in any order, and may repeat:
a = [:foo, 'bar', 2] a.values_at(2, 0, 1, 0, 2) # => [2, :foo, "bar", :foo, 2] a.values_at(1, 0..2) # => ["bar", :foo, "bar", 2]
Assigns nil
for an index
that is too large:
a = [:foo, 'bar', 2] a.values_at(0, 3, 1, 3) # => [:foo, nil, "bar", nil]
Returns a new empty Array
if no arguments given.
For each negative index
, counts backward from the end of the array:
a = [:foo, 'bar', 2] a.values_at(-1, -3) # => [2, :foo]
Assigns nil
for an index
that is too small:
a = [:foo, 'bar', 2] a.values_at(0, -5, 1, -6, 2) # => [:foo, nil, "bar", nil, 2]
The given indexes
may have a mixture of signs:
a = [:foo, 'bar', 2] a.values_at(0, -2, 1, -1) # => [:foo, "bar", "bar", 2]
Deletes an element from self
, per the given Integer
index
.
When index
is non-negative, deletes the element at offset index
:
a = [:foo, 'bar', 2] a.delete_at(1) # => "bar" a # => [:foo, 2]
If index is too large, returns nil
.
When index
is negative, counts backward from the end of the array:
a = [:foo, 'bar', 2] a.delete_at(-2) # => "bar" a # => [:foo, 2]
If index
is too small (far from zero), returns nil.
Searches self
as described at method bsearch
, but returns the index of the found element instead of the element itself.