iterates over the list of Addrinfo
objects obtained by Addrinfo.getaddrinfo
.
Addrinfo.foreach(nil, 80) {|x| p x } #=> #<Addrinfo: 127.0.0.1:80 TCP (:80)> # #<Addrinfo: 127.0.0.1:80 UDP (:80)> # #<Addrinfo: [::1]:80 TCP (:80)> # #<Addrinfo: [::1]:80 UDP (:80)>
Returns true if and only if there is more data in the string. See eos?
. This method is obsolete; use eos?
instead.
s = StringScanner.new('test string') s.eos? # These two s.rest? # are opposites.
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
.
Path input without headers:
string = "foo,0\nbar,1\nbaz,2\n" in_path = 't.csv' File.write(in_path, string) CSV.foreach(in_path) {|row| p row }
Output:
["foo", "0"] ["bar", "1"] ["baz", "2"]
Path input with headers:
string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" in_path = 't.csv' File.write(in_path, string) CSV.foreach(in_path, headers: true) {|row| p row }
Output:
<CSV::Row "Name":"foo" "Value":"0"> <CSV::Row "Name":"bar" "Value":"1"> <CSV::Row "Name":"baz" "Value":"2">
IO stream input without headers:
string = "foo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string) File.open('t.csv') do |in_io| CSV.foreach(in_io) {|row| p row } end
Output:
["foo", "0"] ["bar", "1"] ["baz", "2"]
IO stream input with headers:
string = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string) File.open('t.csv') do |in_io| CSV.foreach(in_io, headers: true) {|row| p row } end
Output:
<CSV::Row "Name":"foo" "Value":"0"> <CSV::Row "Name":"bar" "Value":"1"> <CSV::Row "Name":"baz" "Value":"2">
With no block given, returns an Enumerator:
string = "foo,0\nbar,1\nbaz,2\n" path = 't.csv' File.write(path, string) CSV.foreach(path) # => #<Enumerator: CSV:foreach("t.csv", "r")>
Arguments:
Argument path_or_io
must be a file path or an IO stream.
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.
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