Results for: "String#[]"

Returns whether the [position] is at the beginning of a line; that is, at the beginning of the [stored string] or immediately after a newline:

scanner = StringScanner.new(MULTILINE_TEXT)
scanner.string
# => "Go placidly amid the noise and haste,\nand remember what peace there may be in silence.\n"
scanner.pos                # => 0
scanner.beginning_of_line? # => true

scanner.scan_until(/,/)    # => "Go placidly amid the noise and haste,"
scanner.beginning_of_line? # => false

scanner.scan(/\n/)         # => "\n"
scanner.beginning_of_line? # => true

scanner.terminate
scanner.beginning_of_line? # => true

scanner.concat('x')
scanner.terminate
scanner.beginning_of_line? # => false

StringScanner#bol? is an alias for StringScanner#beginning_of_line?.

Is this handler a streaming handler?

No documentation available

Returns an array of instance variable names for the receiver. Note that simply defining an accessor does not create the corresponding instance variable.

class Fred
  attr_accessor :a1
  def initialize
    @iv = 3
  end
end
Fred.new.instance_variables   #=> [:@iv]

Invoked when a reference is made to an undefined constant in mod. It is passed a symbol for the undefined constant, and returns a value to be used for that constant. For example, consider:

def Foo.const_missing(name)
  name # return the constant name as Symbol
end

Foo::UNDEFINED_CONST    #=> :UNDEFINED_CONST: symbol returned

As the example above shows, const_missing is not required to create the missing constant in mod, though that is often a side-effect. The caller gets its return value when triggered. If the constant is also defined, further lookups won’t hit const_missing and will return the value stored in the constant as usual. Otherwise, const_missing will be invoked again.

In the next example, when a reference is made to an undefined constant, const_missing attempts to load a file whose path is the lowercase version of the constant name (thus class Fred is assumed to be in file fred.rb). If defined as a side-effect of loading the file, the method returns the value stored in the constant. This implements an autoload feature similar to Kernel#autoload and Module#autoload, though it differs in important ways.

def Object.const_missing(name)
  @looked_for ||= {}
  str_name = name.to_s
  raise "Constant not found: #{name}" if @looked_for[str_name]
  @looked_for[str_name] = 1
  file = str_name.downcase
  require file
  const_get(name, false)
end

Returns the Encoding object that represents the encoding of the internal string, if conversion is specified, or nil otherwise.

See Encodings.

Returns the Encoding of the internal string if conversion is specified. Otherwise returns nil.

Returns the internal encoding for strings read from ARGF as an Encoding object.

If ARGF.set_encoding has been called with two encoding names, the second is returned. Otherwise, if Encoding.default_external has been set, that value is returned. Failing that, if a default external encoding was specified on the command-line, that value is used. If the encoding is unknown, nil is returned.

Outputs obj to out like PP.pp but with no indent and newline.

PP.singleline_pp returns out.

Returns the sharing detection flag as a boolean value. It is false (nil) by default.

Sets the sharing detection flag to b.

This is similar to PrettyPrint::format but the result has no breaks.

maxwidth, newline and genspace are ignored.

The invocation of breakable in the block doesn’t break a line and is treated as just an invocation of text.

Closes the incoming port and returns whether it was already closed. All further attempts to Ractor.receive in the ractor, and send to the ractor will fail with Ractor::ClosedError.

r = Ractor.new {sleep(500)}
r.close_incoming  #=> false
r.close_incoming  #=> true
r.send('test')
# Ractor::ClosedError (The incoming-port is already closed)

Returns whether or not the asynchronous queue is empty.

Since Thread::handle_interrupt can be used to defer asynchronous events, this method can be used to determine if there are any deferred events.

If you find this method returns true, then you may finish :never blocks.

For example, the following method processes deferred asynchronous events immediately.

def Thread.kick_interrupt_immediately
  Thread.handle_interrupt(Object => :immediate) {
    Thread.pass
  }
end

If error is given, then check only for error type deferred events.

Usage

th = Thread.new{
  Thread.handle_interrupt(RuntimeError => :on_blocking){
    while true
      ...
      # reach safe point to invoke interrupt
      if Thread.pending_interrupt?
        Thread.handle_interrupt(Object => :immediate){}
      end
      ...
    end
  }
}
...
th.raise # stop thread

This example can also be written as the following, which you should use to avoid asynchronous interrupts.

flag = true
th = Thread.new{
  Thread.handle_interrupt(RuntimeError => :on_blocking){
    while true
      ...
      # reach safe point to invoke interrupt
      break if flag == false
      ...
    end
  }
}
...
flag = false # stop thread

Returns whether or not the asynchronous queue is empty for the target thread.

If error is given, then check only for error type deferred events.

See ::pending_interrupt? for more information.

Returns the compiled instruction sequence represented by a RubyVM::InstructionSequence instance on the :script_compiled event.

Note that this method is CRuby-specific.

Adds a post-install hook that will be passed an Gem::Installer instance when Gem::Installer#install is called

Adds a post-uninstall hook that will be passed a Gem::Uninstaller instance and the spec that was uninstalled when Gem::Uninstaller#uninstall is called

Returns the destination encoding as an encoding object.

Returns the destination encoding as an encoding object.

Returns the destination encoding as an Encoding object.

Returns true if this comment happens on the same line as other code and false if the comment is by itself.

This can only be true for inline comments.

Returns the index of the last element for which object == element.

With argument object given, returns the index of the last such element found:

a = [:foo, 'bar', 2, 'bar']
a.rindex('bar') # => 3

Returns nil if no such object found.

With a block given, calls the block with each successive element; returns the index of the last element for which the block returns a truthy value:

a = [:foo, 'bar', 2, 'bar']
a.rindex {|element| element == 'bar' } # => 3

Returns nil if the block never returns a truthy value.

When neither an argument nor a block is given, returns a new Enumerator.

Related: see Methods for Querying.

Returns 1 if either self.real.infinite? or self.imag.infinite? is true, nil otherwise:

Complex.rect(Float::INFINITY, 0).infinite? # => 1
Complex.rect(1, 1).infinite?               # => nil

Related: Numeric#infinite?, Float#infinite?.

Search took: 5ms  ·  Total Results: 2715