Results for: "Array.new"

No documentation available
No documentation available

Create a new ArrayPatternNode node.

Retrieve the value of one of the ArrayNodeFlags flags.

No documentation available
No documentation available

Compile a ArrayPatternNode node

Dispatch enter and leave events for ArrayPatternNode nodes and continue walking the tree.

Inspect a ArrayPatternNode node.

Copy a ArrayPatternNode node

in [foo, bar, baz]

Returns a new String that is a copy of string.

With no arguments, returns the empty string with the Encoding ASCII-8BIT:

s = String.new
s # => ""
s.encoding # => #<Encoding:ASCII-8BIT>

With optional argument string and no keyword arguments, returns a copy of string with the same encoding:

String.new('foo')               # => "foo"
String.new('тест')              # => "тест"
String.new('こんにちは')          # => "こんにちは"

(Unlike String.new, a string literal like '' or a string literal always has script encoding.)

With optional keyword argument encoding, returns a copy of string with the specified encoding; the encoding may be an Encoding object, an encoding name, or an encoding name alias:

String.new('foo', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
String.new('foo', encoding: 'US-ASCII').encoding         # => #<Encoding:US-ASCII>
String.new('foo', encoding: 'ASCII').encoding            # => #<Encoding:US-ASCII>

The given encoding need not be valid for the string’s content, and that validity is not checked:

s = String.new('こんにちは', encoding: 'ascii')
s.valid_encoding? # => false

But the given encoding itself is checked:

String.new('foo', encoding: 'bar') # Raises ArgumentError.

With optional keyword argument capacity, returns a copy of string (or an empty string, if string is not given); the given capacity is advisory only, and may or may not set the size of the internal buffer, which may in turn affect performance:

String.new(capacity: 1)
String.new('foo', capacity: 4096)

Note that Ruby strings are null-terminated internally, so the internal buffer size will be one or more bytes larger than the requested capacity depending on the encoding.

The string, encoding, and capacity arguments may all be used together:

String.new('hello', encoding: 'UTF-8', capacity: 25)

Creates new Fiber. Initially, the fiber is not running and can be resumed with resume. Arguments to the first resume call will be passed to the block:

f = Fiber.new do |initial|
   current = initial
   loop do
     puts "current: #{current.inspect}"
     current = Fiber.yield
   end
end
f.resume(100)     # prints: current: 100
f.resume(1, 2, 3) # prints: current: [1, 2, 3]
f.resume          # prints: current: nil
# ... and so on ...

If blocking: false is passed to Fiber.new, and current thread has a Fiber.scheduler defined, the Fiber becomes non-blocking (see “Non-blocking Fibers” section in class docs).

If the storage is unspecified, the default is to inherit a copy of the storage from the current fiber. This is the same as specifying storage: true.

Fiber[:x] = 1
Fiber.new do
  Fiber[:x] # => 1
  Fiber[:x] = 2
end.resume
Fiber[:x] # => 1

If the given storage is nil, this function will lazy initialize the internal storage, which starts as an empty hash.

Fiber[:x] = "Hello World"
Fiber.new(storage: nil) do
  Fiber[:x] # nil
end

Otherwise, the given storage is used as the new fiber’s storage, and it must be an instance of Hash.

Explicitly using storage: true is currently experimental and may change in the future.

Returns a new Dir object for the directory at dirpath:

Dir.new('.') # => #<Dir:.>

The value given with optional keyword argument encoding specifies the encoding for the directory entry names; if nil (the default), the file system’s encoding is used:

Dir.new('.').read.encoding                       # => #<Encoding:UTF-8>
Dir.new('.', encoding: 'US-ASCII').read.encoding # => #<Encoding:US-ASCII>

Opens the file at the given path according to the given mode; creates and returns a new File object for that file.

The new File object is buffered mode (or non-sync mode), unless filename is a tty. See IO#flush, IO#fsync, IO#fdatasync, and IO#sync=.

Argument path must be a valid file path:

f = File.new('/etc/fstab')
f.close
f = File.new('t.txt')
f.close

Optional argument mode (defaults to ‘r’) must specify a valid mode; see Access Modes:

f = File.new('t.tmp', 'w')
f.close
f = File.new('t.tmp', File::RDONLY)
f.close

Optional argument perm (defaults to 0666) must specify valid permissions see File Permissions:

f = File.new('t.tmp', File::CREAT, 0644)
f.close
f = File.new('t.tmp', File::CREAT, 0444)
f.close

Optional keyword arguments opts specify:

Creates a new Enumerator object, which can be used as an Enumerable.

Iteration is defined by the given block, in which a “yielder” object, given as block parameter, can be used to yield a value by calling the yield method (aliased as <<):

fib = Enumerator.new do |y|
  a = b = 1
  loop do
    y << a
    a, b = b, a + b
  end
end

fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

The optional parameter can be used to specify how to calculate the size in a lazy fashion (see Enumerator#size). It can either be a value or a callable object.

Returns a new exception object.

The given message should be a string-convertible object; see method message; if not given, the message is the class name of the new instance (which may be the name of a subclass):

Examples:

Exception.new         # => #<Exception: Exception>
LoadError.new         # => #<LoadError: LoadError> # Subclass of Exception.
Exception.new('Boom') # => #<Exception: Boom>

Create a new SystemExit exception with the given status and message. Status is true, false, or an integer. If status is not given, true is used.

Construct a new SignalException object. sig_name should be a known signal name.

Construct a new KeyError exception with the given message, receiver and key.

Construct a SyntaxError exception.

Construct a new NameError exception. If given the name parameter may subsequently be examined using the NameError#name method. receiver parameter allows to pass object in context of which the error happened. Example:

[1, 2, 3].method(:rject) # NameError with name "rject" and receiver: Array
[1, 2, 3].singleton_method(:rject) # NameError with name "rject" and receiver: [1, 2, 3]

Construct a NoMethodError exception for a method of the given name called with the given arguments. The name may be accessed using the name method on the resulting object, and the arguments using the args method.

If private argument were passed, it designates method was attempted to call in private context, and can be accessed with private_call? method.

receiver argument stores an object whose method was called.

Construct a new FrozenError exception. If given the receiver parameter may subsequently be examined using the FrozenError#receiver method.

a = [].freeze
raise FrozenError.new("can't modify frozen array", receiver: a)

Construct a new NoMatchingPatternKeyError exception with the given message, matchee and key.

Search took: 6ms  ·  Total Results: 3535