Returns the “rest” of the string (i.e. everything after the scan pointer). If there is no more data (eos? = true), it returns ""
.
s.restsize
is equivalent to s.rest_size
. This method is obsolete; use rest_size
instead.
Returns help string of OLE method. If the help string is not found, then the method returns nil.
tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', 'IWebBrowser') method = WIN32OLE_METHOD.new(tobj, 'Navigate') puts method.helpstring # => Navigates to a URL or file.
Returns help string.
tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', 'IWebBrowser') puts tobj.helpstring # => Web Browser interface
Calls the block with each row read from source path
or io
.
Argument path
, if given, must be the path to a file.
Argument io
should be an IO
object that is:
Open for reading; on return, the IO
object will be closed.
Positioned at the beginning. To position at the end, for appending, use method CSV.generate
. For any other positioning, pass a preset StringIO object instead.
Argument mode
, if given, must be a File mode See Open Mode.
Arguments **options
must be keyword options. See Options for Parsing.
This method optionally accepts an additional :encoding
option that you can use to specify the Encoding
of the data read from path
or io
. You must provide this unless your data is in the encoding given by Encoding::default_external
. Parsing will use this to determine how to parse the data. You may provide a second Encoding
to have the data transcoded as it is read. For example,
encoding: 'UTF-32BE:UTF-8'
would read UTF-32BE
data from the file but transcode it to UTF-8
before parsing.
headers
Without option headers
, returns each row as an Array object.
These examples assume prior execution of:
string = "foo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string)
Read rows from a file at path
:
CSV.foreach(path) {|row| p row }
Output:
["foo", "0"] ["bar", "1"] ["baz", "2"]
Read rows from an IO object:
File.open(path) do |file| CSV.foreach(file) {|row| p row } end
Output:
["foo", "0"] ["bar", "1"] ["baz", "2"]
Returns a new Enumerator if no block given:
CSV.foreach(path) # => #<Enumerator: CSV:foreach("t.csv", "r")> CSV.foreach(File.open(path)) # => #<Enumerator: CSV:foreach(#<File:t.csv>, "r")>
Issues a warning if an encoding is unsupported:
CSV.foreach(File.open(path), encoding: 'foo:bar') {|row| }
Output:
warning: Unsupported encoding foo ignored warning: Unsupported encoding bar ignored
headers
With {option headers
}, returns each row as a CSV::Row
object.
These examples assume prior execution of:
string = "Name,Count\nfoo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string)
Read rows from a file at path
:
CSV.foreach(path, headers: true) {|row| p row }
Output:
#<CSV::Row "Name":"foo" "Count":"0"> #<CSV::Row "Name":"bar" "Count":"1"> #<CSV::Row "Name":"baz" "Count":"2">
Read rows from an IO object:
File.open(path) do |file| CSV.foreach(file, headers: true) {|row| p row } end
Output:
#<CSV::Row "Name":"foo" "Count":"0"> #<CSV::Row "Name":"bar" "Count":"1"> #<CSV::Row "Name":"baz" "Count":"2">
Raises an exception if path
is a String, but not the path to a readable file:
# Raises Errno::ENOENT (No such file or directory @ rb_sysopen - nosuch.csv): CSV.foreach('nosuch.csv') {|row| }
Raises an exception if io
is an IO object, but not open for reading:
io = File.open(path, 'w') {|row| } # Raises TypeError (no implicit conversion of nil into String): CSV.foreach(io) {|row| }
Raises an exception if mode
is invalid:
# Raises ArgumentError (invalid access mode nosuch): CSV.foreach(path, 'nosuch') {|row| }
Returns the (row, column) cofactor which is obtained by multiplying the first minor by (-1)**(row + column).
Matrix.diagonal(9, 5, -3, 4).cofactor(1, 1) # => -108
Creates a single-row matrix from this vector.
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
Loads the given name
, returning true
if successful and false
if the feature is already loaded.
If the filename neither resolves to an absolute path nor starts with ‘./’ or ‘../’, the file will be searched for in the library directories listed in $LOAD_PATH
($:
). If the filename starts with ‘./’ or ‘../’, resolution is based on Dir.pwd
.
If the filename has the extension “.rb”, it is loaded as a source file; if the extension is “.so”, “.o”, or “.dll”, or the default shared library extension on the current platform, Ruby loads the shared library as a Ruby extension. Otherwise, Ruby tries adding “.rb”, “.so”, and so on to the name until found. If the file named cannot be found, a LoadError
will be raised.
For Ruby extensions the filename given may use any shared library extension. For example, on Linux the socket extension is “socket.so” and require 'socket.dll'
will load the socket extension.
The absolute path of the loaded file is added to $LOADED_FEATURES
($"
). A file will not be loaded again if its path already appears in $"
. For example, require 'a'; require './a'
will not load a.rb
again.
require "my-library.rb" require "db-driver"
Any constants or globals within the loaded source file will be available in the calling program’s global namespace. However, local variables will not be propagated to the loading environment.
Deprecated. Use block_given? instead.
Returns 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.
flag can be true, false, or an integer bit-ORed 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
.