Results for: "Data"

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 a new Array containing the first n element of self, where n is a non-negative Integer; does not modify self.

Examples:

a = [0, 1, 2, 3, 4, 5]
a.take(1) # => [0]
a.take(2) # => [0, 1]
a.take(50) # => [0, 1, 2, 3, 4, 5]
a # => [0, 1, 2, 3, 4, 5]

Returns self truncated (toward zero) to a precision of ndigits decimal digits.

When ndigits is negative, the returned value has at least ndigits.abs trailing zeros:

555.truncate(-1)  # => 550
555.truncate(-2)  # => 500
-555.truncate(-2) # => -500

Returns self when ndigits is zero or positive.

555.truncate     # => 555
555.truncate(50) # => 555

Related: Integer#round.

Returns self.

Returns 1.

Returns the value as a rational. The optional argument eps is always ignored.

Return the class or module refined by the receiver.

module M
  refine String do
  end
end

M.refinements[0].target # => String

Returns a new Complex object formed from the arguments, each of which must be an instance of Numeric, or an instance of one of its subclasses: Complex, Float, Integer, Rational; see Rectangular Coordinates:

Complex.rect(3)             # => (3+0i)
Complex.rect(3, Math::PI)   # => (3+3.141592653589793i)
Complex.rect(-3, -Math::PI) # => (-3-3.141592653589793i)

Complex.rectangular is an alias for Complex.rect.

Returns the array [self.real, self.imag]:

Complex.rect(1, 2).rect # => [1, 2]

See Rectangular Coordinates.

If self was created with polar coordinates, the returned value is computed, and may be inexact:

Complex.polar(1.0, 1.0).rect # => [0.5403023058681398, 0.8414709848078965]

Complex#rectangular is an alias for Complex#rect.

Returns the conjugate of self, Complex.rect(self.imag, self.real):

Complex.rect(1, 2).conj # => (1-2i)

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 array [self, 0].

Returns self truncated (toward zero) to a precision of digits decimal digits.

Numeric implements this by converting self to a Float and invoking Float#truncate.

Returns true if self is less than 0, false otherwise.

Returns self.

Returns the numerator.

Returns the denominator (always positive).

Returns a MatchData object (or nil) based on self and the given pattern.

Note: also updates Global Variables at Regexp.

With no block given, returns the computed matchdata:

'foo'.match('f') # => #<MatchData "f">
'foo'.match('o') # => #<MatchData "o">
'foo'.match('x') # => nil

If Integer argument offset is given, the search begins at index offset:

'foo'.match('f', 1) # => nil
'foo'.match('o', 1) # => #<MatchData "o">

With a block given, calls the block with the computed matchdata and returns the block’s return value:

'foo'.match(/o/) {|matchdata| matchdata } # => #<MatchData "o">
'foo'.match(/x/) {|matchdata| matchdata } # => nil
'foo'.match(/f/, 1) {|matchdata| matchdata } # => nil

Returns true or false based on whether a match is found for self and pattern.

Note: does not update Global Variables at Regexp.

Computes regexp by converting pattern (if not already a Regexp).

regexp = Regexp.new(pattern)

Returns true if self+.match(regexp) returns a MatchData object, false otherwise:

'foo'.match?(/o/) # => true
'foo'.match?('o') # => true
'foo'.match?(/x/) # => false

If Integer argument offset is given, the search begins at index offset:

'foo'.match?('f', 1) # => false
'foo'.match?('o', 1) # => true

Returns a string containing the characters in self; the first character is upcased; the remaining characters are downcased:

s = 'hello World!' # => "hello World!"
s.capitalize       # => "Hello world!"

The casing may be affected by the given options; see Case Mapping.

Related: String#capitalize!.

Upcases the first character in self; downcases the remaining characters; returns self if any changes were made, nil otherwise:

s = 'hello World!' # => "hello World!"
s.capitalize!      # => "Hello world!"
s                  # => "Hello world!"
s.capitalize!      # => nil

The casing may be affected by the given options; see Case Mapping.

Related: String#capitalize.

Concatenates each object in objects to self and returns self:

s = 'foo'
s.concat('bar', 'baz') # => "foobarbaz"
s                      # => "foobarbaz"

For each given object object that is an Integer, the value is considered a codepoint and converted to a character before concatenation:

s = 'foo'
s.concat(32, 'bar', 32, 'baz') # => "foo bar baz"

Related: String#<<, which takes a single argument.

Search took: 10ms  ·  Total Results: 1843