Results for: "module_function"

Returns the new String formed by calling method #inspect on each array element:

a = [:foo, 'bar', 2]
a.inspect # => "[:foo, \"bar\", 2]"

Array#to_s is an alias for Array#inspect.

Returns a new Array containing only those elements from self that are not found in any of the Arrays other_arrays; items are compared using eql?; order from self is preserved:

[0, 1, 1, 2, 1, 1, 3, 1, 1].difference([1]) # => [0, 2, 3]
[0, 1, 2, 3].difference([3, 0], [1, 3]) # => [2]
[0, 1, 2].difference([4]) # => [0, 1, 2]

Returns a copy of self if no arguments given.

Related: Array#-.

Returns true if the array and other_ary have at least one element in common, otherwise returns false.

a = [ 1, 2, 3 ]
b = [ 3, 4, 5 ]
c = [ 5, 6, 7 ]
a.intersect?(b)   #=> true
a.intersect?(c)   #=> false

Prepends the given objects to self:

a = [:foo, 'bar', 2]
a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2]

Array#prepend is an alias for Array#unshift.

Related: push, pop, shift.

Returns a new Array whose elements are all those from self for which the block returns false or nil:

a = [:foo, 'bar', 2, 'bat']
a1 = a.reject {|element| element.to_s.start_with?('b') }
a1 # => [:foo, 2]

Returns a new Enumerator if no block given:

a = [:foo, 'bar', 2]
a.reject # => #<Enumerator: [:foo, "bar", 2]:reject>

Removes each element for which the block returns a truthy value.

Returns self if any elements removed:

a = [:foo, 'bar', 2, 'bat']
a.reject! {|element| element.to_s.start_with?('b') } # => [:foo, 2]

Returns nil if no elements removed.

Returns a new Enumerator if no block given:

a = [:foo, 'bar', 2]
a.reject! # => #<Enumerator: [:foo, "bar", 2]:reject!>

Returns true if for some index i in self, obj == self[i]; otherwise false:

[0, 1, 2].include?(2) # => true
[0, 1, 2].include?(3) # => false

Returns a new Array containing those elements from self that are not duplicates, the first occurrence always being retained.

With no block given, identifies and omits duplicates using method eql? to compare.

a = [0, 0, 1, 1, 2, 2]
a.uniq # => [0, 1, 2]

With a block given, calls the block for each element; identifies (using method eql?) and omits duplicate values, that is, those elements for which the block returns the same value:

a = ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
a.uniq {|element| element.size } # => ["a", "aa", "aaa"]

Removes duplicate elements from self, the first occurrence always being retained; returns self if any elements removed, nil otherwise.

With no block given, identifies and removes elements using method eql? to compare.

Returns self if any elements removed:

a = [0, 0, 1, 1, 2, 2]
a.uniq! # => [0, 1, 2]

Returns nil if no elements removed.

With a block given, calls the block for each element; identifies (using method eql?) and removes elements for which the block returns duplicate values.

Returns self if any elements removed:

a = ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
a.uniq! {|element| element.size } # => ['a', 'aa', 'aaa']

Returns nil if no elements removed.

Returns a new Array containing all non-nil elements from self:

a = [nil, 0, nil, 1, nil, 2, nil]
a.compact # => [0, 1, 2]

Removes all nil elements from self.

Returns self if any elements removed, otherwise nil.

Returns a count of specified elements.

With no argument and no block, returns the count of all elements:

[0, 1, 2].count # => 3
[].count # => 0

With argument obj, returns the count of elements == to obj:

[0, 1, 2, 0.0].count(0) # => 2
[0, 1, 2].count(3) # => 0

With no argument and a block given, calls the block with each element; returns the count of elements for which the block returns a truthy value:

[0, 1, 2, 3].count {|element| element > 1} # => 2

With argument obj and a block given, issues a warning, ignores the block, and returns the count of elements == to obj:

Returns true if no element of self meet a given criterion.

With no block given and no argument, returns true if self has no truthy elements, false otherwise:

[nil, false].none? # => true
[nil, 0, false].none? # => false
[].none? # => true

With a block given and no argument, calls the block with each element in self; returns true if the block returns no truthy value, false otherwise:

[0, 1, 2].none? {|element| element > 3 } # => true
[0, 1, 2].none? {|element| element > 1 } # => false

If argument obj is given, returns true if obj.=== no element, false otherwise:

['food', 'drink'].none?(/bar/) # => true
['food', 'drink'].none?(/foo/) # => false
[].none?(/foo/) # => true
[0, 1, 2].none?(3) # => true
[0, 1, 2].none?(1) # => false

Related: Enumerable#none?

Returns true if exactly one element of self meets a given criterion.

With no block given and no argument, returns true if self has exactly one truthy element, false otherwise:

[nil, 0].one? # => true
[0, 0].one? # => false
[nil, nil].one? # => false
[].one? # => false

With a block given and no argument, calls the block with each element in self; returns true if the block a truthy value for exactly one element, false otherwise:

[0, 1, 2].one? {|element| element > 0 } # => false
[0, 1, 2].one? {|element| element > 1 } # => true
[0, 1, 2].one? {|element| element > 2 } # => false

If argument obj is given, returns true if obj.=== exactly one element, false otherwise:

[0, 1, 2].one?(0) # => true
[0, 0, 1].one?(0) # => false
[1, 1, 2].one?(0) # => false
['food', 'drink'].one?(/bar/) # => false
['food', 'drink'].one?(/foo/) # => true
[].one?(/foo/) # => false

Related: Enumerable#one?

Returns object. This method is deprecated and will be removed in Ruby 3.2.

Returns object. This method is deprecated and will be removed in Ruby 3.2.

Returns false. This method is deprecated and will be removed in Ruby 3.2.

Returns a string containing a human-readable representation of obj. The default inspect shows the object’s class name, an encoding of its memory address, and a list of the instance variables and their values (by calling inspect on each of them). User defined classes should override this method to provide a better representation of obj. When overriding this method, it should return a string whose encoding is compatible with the default external encoding.

[ 1, 2, 3..4, 'five' ].inspect   #=> "[1, 2, 3..4, \"five\"]"
Time.new.inspect                 #=> "2008-03-08 19:43:39 +0900"

class Foo
end
Foo.new.inspect                  #=> "#<Foo:0x0300c868>"

class Bar
  def initialize
    @bar = 1
  end
end
Bar.new.inspect                  #=> "#<Bar:0x0300c868 @bar=1>"

Calls the given block self times with each integer in (0..self-1):

a = []
5.times {|i| a.push(i) } # => 5
a                        # => [0, 1, 2, 3, 4]

With no block given, returns an Enumerator.

Returns self rounded to the nearest value with a precision of ndigits decimal digits.

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

555.round(-1)      # => 560
555.round(-2)      # => 600
555.round(-3)      # => 1000
-555.round(-2)     # => -600
555.round(-4)      # => 0

Returns self when ndigits is zero or positive.

555.round     # => 555
555.round(1)  # => 555
555.round(50) # => 555

If keyword argument half is given, and self is equidistant from the two candidate values, the rounding is according to the given half value:

Raises and exception if the value for half is invalid.

Related: Integer#truncate.

Returns a string containing the place-value representation of self in radix base (in 2..36).

12345.to_s               # => "12345"
12345.to_s(2)            # => "11000000111001"
12345.to_s(8)            # => "30071"
12345.to_s(10)           # => "12345"
12345.to_s(16)           # => "3039"
12345.to_s(36)           # => "9ix"
78546939656932.to_s(36)  # => "rubyrules"

Raises an exception if base is out of range.

Integer#inspect is an alias for Integer#to_s.

Returns a complex object which denotes the given rectangular form.

Complex.rectangular(1, 2)  #=> (1+2i)

Returns a complex object which denotes the given rectangular form.

Complex.rectangular(1, 2)  #=> (1+2i)

Returns the complex conjugate.

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

Returns the complex conjugate.

Complex(1, 2).conjugate  #=> (1-2i)
Search took: 6ms  ·  Total Results: 3178