Returns the ‘rest’ of the [stored string] (all after the current [position]), which is the [target substring]:
scanner = StringScanner.new('foobarbaz') scanner.rest # => "foobarbaz" scanner.pos = 3 scanner.rest # => "barbaz" scanner.terminate scanner.rest # => ""
Add separator in summary.
Stops execution of the current thread, putting it into a “sleep” state, and schedules execution of another thread.
a = Thread.new { print "a"; Thread.stop; print "c" } sleep 0.1 while a.status!='sleep' print "b" a.run a.join #=> "abc"
Returns true
if thr
is dead or sleeping.
a = Thread.new { Thread.stop } b = Thread.current a.stop? #=> true b.stop? #=> false
When RubyGems is required, Kernel#require
is replaced with our own which is capable of loading gems on demand.
When you call require 'x'
, this is what happens:
If the file can be loaded from the existing Ruby loadpath, it is.
Otherwise, installed gems are searched for a file that matches. If it’s found in gem ‘y’, that gem is activated (added to the loadpath).
The normal require
functionality of returning false if that file has already been loaded is preserved.
Deprecated. Use block_given? instead.
Returns the current status of GC stress mode.
Updates the GC stress mode.
When stress mode is enabled, the GC is invoked at every GC opportunity: all memory and object allocations.
Enabling stress mode will degrade performance; it is only for debugging.
The flag can be true, false, or an integer bitwise-ORed with the following flags:
0x01:: no major GC 0x02:: no immediate sweep 0x04:: full mark after malloc/calloc/realloc
Refresh available gems from disk.
Breaks the buffer into lines that are shorter than maxwidth
Shortcut for defining multiple delegator methods, but with no provision for using a different name. The following two code samples have the same effect:
def_delegators :@records, :size, :<<, :map def_delegator :@records, :size def_delegator :@records, :<< def_delegator :@records, :map
Define method
as delegator instance method with an optional alias name ali
. Method
calls to ali
will be delegated to accessor.method
. accessor
should be a method name, instance variable name, or constant name. Use the full path to the constant if providing the constant name. Returns the name of the method defined.
class MyQueue CONST = 1 extend Forwardable attr_reader :queue def initialize @queue = [] end def_delegator :@queue, :push, :mypush def_delegator 'MyQueue::CONST', :to_i end q = MyQueue.new q.mypush 42 q.queue #=> [42] q.push 23 #=> NoMethodError q.to_i #=> 1
Called with encoding
when the YAML
stream starts. This method is called once per stream. A stream may contain multiple documents.
See the constants in Psych::Parser
for the possible values of encoding
.
Sends a POST request to the server; forms the response into a Net::HTTPResponse
object.
The request is based on the Net::HTTP::Post
object created from string path
, string data
, and initial headers hash initheader
.
With no block given, returns the response object:
http = Net::HTTP.new(hostname) http.post('/todos', 'xyzzy') # => #<Net::HTTPCreated 201 Created readbody=true>
With a block given, calls the block with the response body and returns the response object:
http.post('/todos', 'xyzzy') do |res| p res end # => #<Net::HTTPCreated 201 Created readbody=true>
Output:
"{\n \"xyzzy\": \"\",\n \"id\": 201\n}"