v
Public setter for the path component v
(with validation).
See also URI::Generic.check_path
.
require 'uri' uri = URI.parse("http://my.example.com/pub/files") uri.path = "/faq/" uri.to_s #=> "http://my.example.com/faq/"
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>,
Create a new BlockParameterNode
node
Create a new BlockParametersNode
node
Create a new ConstantPathAndWriteNode
node
Create a new ConstantPathOrWriteNode
node
Create a new ConstantPathTargetNode
node
Create a new ConstantPathWriteNode
node
Create a new ForwardingParameterNode
node
Create a new KeywordRestParameterNode
node
Create a new NoKeywordsParameterNode
node
Create a new NumberedParametersNode
node
Create a new ParametersNode
node
Create a new RequiredKeywordParameterNode
node
Create a new RequiredParameterNode
node
Create a new RestParameterNode
node
Calls the block, if given, with combinations of elements of self
; returns self
. The order of combinations is indeterminate.
When a block and an in-range positive Integer
argument n
(0 < n <= self.size
) are given, calls the block with all n
-tuple combinations of self
.
Example:
a = [0, 1, 2] a.combination(2) {|combination| p combination }
Output:
[0, 1] [0, 2] [1, 2]
Another example:
a = [0, 1, 2] a.combination(3) {|combination| p combination }
Output:
[0, 1, 2]
When n
is zero, calls the block once with a new empty Array:
a = [0, 1, 2] a1 = a.combination(0) {|combination| p combination }
Output:
[]
When n
is out of range (negative or larger than self.size
), does not call the block:
a = [0, 1, 2] a.combination(-1) {|combination| fail 'Cannot happen' } a.combination(4) {|combination| fail 'Cannot happen' }
Returns a new Enumerator
if no block given:
a = [0, 1, 2] a.combination(2) # => #<Enumerator: [0, 1, 2]:combination(2)>
Returns self
.
Returns 1
.
Returns the value as a rational. The optional argument eps
is always ignored.
Returns the Complex object created from the numerators of the real and imaginary parts of self
, after converting each part to the lowest common denominator of the two:
c = Complex(Rational(2, 3), Rational(3, 4)) # => ((2/3)+(3/4)*i) c.numerator # => (8+9i)
In this example, the lowest common denominator of the two parts is 12; the two converted parts may be thought of as Rational(8, 12) and Rational(9, 12), whose numerators, respectively, are 8 and 9; so the returned value of c.numerator
is Complex(8, 9)
.
Related: Complex#denominator
.
Returns the denominator of self
, which is the least common multiple of self.real.denominator
and self.imag.denominator
:
Complex.rect(Rational(1, 2), Rational(2, 3)).denominator # => 6
Note that n.denominator
of a non-rational numeric is 1
.
Related: Complex#numerator
.
Returns a Rational
object whose value is exactly or approximately equivalent to that of self.real
.
With no argument epsilon
given, returns a Rational object whose value is exactly equal to that of self.real.rationalize
:
Complex(1, 0).rationalize # => (1/1) Complex(1, Rational(0, 1)).rationalize # => (1/1) Complex(3.14159, 0).rationalize # => (314159/100000)
With argument epsilon
given, returns a Rational object whose value is exactly or approximately equal to that of self.real
to the given precision:
Complex(3.14159, 0).rationalize(0.1) # => (16/5) Complex(3.14159, 0).rationalize(0.01) # => (22/7) Complex(3.14159, 0).rationalize(0.001) # => (201/64) Complex(3.14159, 0).rationalize(0.0001) # => (333/106) Complex(3.14159, 0).rationalize(0.00001) # => (355/113) Complex(3.14159, 0).rationalize(0.000001) # => (7433/2366) Complex(3.14159, 0).rationalize(0.0000001) # => (9208/2931) Complex(3.14159, 0).rationalize(0.00000001) # => (47460/15107) Complex(3.14159, 0).rationalize(0.000000001) # => (76149/24239) Complex(3.14159, 0).rationalize(0.0000000001) # => (314159/100000) Complex(3.14159, 0).rationalize(0.0) # => (3537115888337719/1125899906842624)
Related: Complex#to_r
.
Returns zero as a Rational:
nil.rationalize # => (0/1)
Argument eps
is ignored.
Returns the numerator.