Results for: "to_proc"

Returns self.

If called on a subclass of String, converts the receiver to a String object.

Returns the Symbol corresponding to str, creating the symbol if it did not previously exist. See Symbol#id2name.

"Koala".intern         #=> :Koala
s = 'cat'.to_sym       #=> :cat
s == :cat              #=> true
s = '@cat'.to_sym      #=> :@cat
s == :@cat             #=> true

This can also be used to create symbols that cannot be represented using the :xxx notation.

'cat and dog'.to_sym   #=> :"cat and dog"

Returns the float truncated to an Integer.

Synonyms are to_i, to_int, and truncate.

Returns the path parameter passed to dir’s constructor.

d = Dir.new("..")
d.path   #=> ".."

Returns the pathname used to create file as a string. Does not normalize the name.

File.new("testfile").path               #=> "testfile"
File.new("/tmp/../tmp/xxx", "w").path   #=> "/tmp/../tmp/xxx"

Creates a new Enumerator which will enumerate by calling method on obj, passing args if any.

If a block is given, it will be used to calculate the size of the enumerator without the need to iterate it (see Enumerator#size).

Examples

str = "xyz"

enum = str.enum_for(:each_byte)
enum.each { |b| puts b }
# => 120
# => 121
# => 122

# protect an array from being modified by some_method
a = [1, 2, 3]
some_method(a.to_enum)

It is typical to call to_enum when defining methods for a generic Enumerable, in case no block is passed.

Here is such an example, with parameter passing and a sizing block:

module Enumerable
  # a generic method to repeat the values of any enumerable
  def repeat(n)
    raise ArgumentError, "#{n} is negative!" if n < 0
    unless block_given?
      return to_enum(__method__, n) do # __method__ is :repeat here
        sz = size     # Call size and multiply by n...
        sz * n if sz  # but return nil if size itself is nil
      end
    end
    each do |*val|
      n.times { yield *val }
    end
  end
end

%i[hello world].repeat(2) { |w| puts w }
  # => Prints 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
  # => returns an Enumerator when called without a block
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
No documentation available

Stores class name (Exception) with message m and backtrace array b as JSON string

Returns the value as an integer (Fixnum or Bignum).

If the BigNumber is infinity or NaN, raises FloatDomainError.

Converts a BigDecimal to a String of the form “nnnnnn.mmm”. This method is deprecated; use BigDecimal#to_s(“F”) instead.

require 'bigdecimal'
require 'bigdecimal/util'

d = BigDecimal.new("3.14")
d.to_digits
# => "3.14"

return the JSON value

Casts an Integer as an OpenSSL::BN

See ‘man bn` for more info.

As int is already an Integer, all these methods simply return the receiver.

Synonyms are to_int, floor, ceil, truncate.

Stores class name (Rational) along with numerator value n and denominator value d as JSON string

Returns a Time object which denotes self.

Returns self;

Returns a DateTime object which denotes self.

Stores class name (Date) with Julian year y, month m, day d and Day of Calendar Reform sg as JSON string

Returns a Time object which denotes self.

Returns a Date object which denotes self.

Returns self.

Stores class name (DateTime) with Julian year y, month m, day d, hour H, minute M, second S, offset of and Day of Calendar Reform sg as JSON string

Returns a copy of self as local mode.

Returns a Date object which denotes self.

Returns a DateTime object which denotes self.

Search took: 2ms  ·  Total Results: 1874