Returns Ruby object wrapping OLE variant. The first argument specifies Ruby object to convert OLE variant variable. The second argument specifies VARIANT
type. In some situation, you need the WIN32OLE_VARIANT object to pass OLE method
shell = WIN32OLE.new("Shell.Application") folder = shell.NameSpace("C:\\Windows") item = folder.ParseName("tmp.txt") # You can't use Ruby String object to call FolderItem.InvokeVerb. # Instead, you have to use WIN32OLE_VARIANT object to call the method. shortcut = WIN32OLE_VARIANT.new("Create Shortcut(\&S)") item.invokeVerb(shortcut)
Creates a new deflate stream for compression. If a given argument is nil, the default value of that argument is used.
The level
sets the compression level for the deflate stream between 0 (no compression) and 9 (best compression). The following constants have been defined to make code more readable:
Zlib::DEFAULT_COMPRESSION
Zlib::NO_COMPRESSION
Zlib::BEST_SPEED
Zlib::BEST_COMPRESSION
See www.zlib.net/manual.html#Constants for further information.
The window_bits
sets the size of the history buffer and should be between 8 and 15. Larger values of this parameter result in better compression at the expense of memory usage.
The mem_level
specifies how much memory should be allocated for the internal compression state. 1 uses minimum memory but is slow and reduces compression ratio while 9 uses maximum memory for optimal speed. The default value is 8. Two constants are defined:
Zlib::DEF_MEM_LEVEL
Zlib::MAX_MEM_LEVEL
The strategy
sets the deflate compression strategy. The following strategies are available:
For normal data
For data produced by a filter or predictor
Prevents dynamic Huffman codes
Prevents string matching
Designed for better compression of PNG image data
See the constants for further description.
open "compressed.file", "w+" do |io| io << Zlib::Deflate.new.deflate(File.read("big.file")) end
open "compressed.file", "w+" do |compressed_io| deflate = Zlib::Deflate.new(Zlib::BEST_COMPRESSION, Zlib::MAX_WBITS, Zlib::MAX_MEM_LEVEL, Zlib::HUFFMAN_ONLY) begin open "big.file" do |big_io| until big_io.eof? do compressed_io << zd.deflate(big_io.read(16384)) end end ensure deflate.close end end
While this example will work, for best optimization review the flags for your specific time, memory usage and output space requirements.
Creates a new inflate stream for decompression. window_bits
sets the size of the history buffer and can have the following values:
Have inflate use the window size from the zlib header of the compressed stream.
Overrides the window size of the inflate header in the compressed stream. The window size must be greater than or equal to the window size of the compressed stream.
Add 32 to window_bits to enable zlib and gzip decoding with automatic header detection, or add 16 to decode only the gzip format (a Zlib::DataError
will be raised for a non-gzip stream).
Enables raw deflate mode which will not generate a check value, and will not look for any check values for comparison at the end of the stream.
This is for use with other formats that use the deflate compressed data format such as zip which provide their own check values.
open "compressed.file" do |compressed_io| zi = Zlib::Inflate.new(Zlib::MAX_WBITS + 32) begin open "uncompressed.file", "w+" do |uncompressed_io| uncompressed_io << zi.inflate(compressed_io.read) end ensure zi.close end end
Creates a GzipWriter
object associated with io
. level
and strategy
should be the same as the arguments of Zlib::Deflate.new
. The GzipWriter
object writes gzipped data to io
. io
must respond to the write
method that behaves the same as IO#write
.
The options
hash may be used to set the encoding of the data. :external_encoding
, :internal_encoding
and :encoding
may be set as in IO::new
.
Creates a GzipReader
object associated with io
. The GzipReader
object reads gzipped data from io
, and parses/decompresses it. The io
must have a read
method that behaves same as the IO#read
.
The options
hash may be used to set the encoding of the data. :external_encoding
, :internal_encoding
and :encoding
may be set as in IO::new
.
If the gzip file header is incorrect, raises an Zlib::GzipFile::Error
exception.
File::Stat.new(file_name) -> stat
Create a File::Stat
object for the given file name (raising an exception if the file doesn’t exist).
Create a new zero-filled IO::Buffer
of size
bytes. By default, the buffer will be internal: directly allocated chunk of the memory. But if the requested size
is more than OS-specific IO::Buffer::PAGE_SIZE
, the buffer would be allocated using the virtual memory mechanism (anonymous mmap
on Unix, VirtualAlloc
on Windows). The behavior can be forced by passing IO::Buffer::MAPPED
as a second parameter.
buffer = IO::Buffer.new(4) # => # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL> # 0x00000000 00 00 00 00 .... buffer.get_string(0, 1) # => "\x00" buffer.set_string("test") buffer # => # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL> # 0x00000000 74 65 73 74 test
Takes source
, which can be a string of Ruby code, or an open File
object. that contains Ruby source code.
Optionally takes file
, path
, and line
which describe the file path, real path and first line number of the ruby code in source
which are metadata attached to the returned iseq
.
file
is used for ‘__FILE__` and exception backtrace. path
is used for require_relative
base. It is recommended these should be the same full path.
options
, which can be true
, false
or a Hash
, is used to modify the default behavior of the Ruby iseq compiler.
For details regarding valid compile options see ::compile_option=
.
RubyVM::InstructionSequence.compile("a = 1 + 2") #=> <RubyVM::InstructionSequence:<compiled>@<compiled>> path = "test.rb" RubyVM::InstructionSequence.compile(File.read(path), path, File.expand_path(path)) #=> <RubyVM::InstructionSequence:<compiled>@test.rb:1> file = File.open("test.rb") RubyVM::InstructionSequence.compile(file) #=> <RubyVM::InstructionSequence:<compiled>@<compiled>:1> path = File.expand_path("test.rb") RubyVM::InstructionSequence.compile(File.read(path), path, path) #=> <RubyVM::InstructionSequence:<compiled>@/absolute/path/to/test.rb:1>
Returns an initialized Tms
object which has utime
as the user CPU time, stime
as the system CPU time, cutime
as the children’s user CPU time, cstime
as the children’s system CPU time, real
as the elapsed real time and label
as the label.
Create a new CGI::Cookie
object.
name_string
The name of the cookie; in this form, there is no domain
or expiration. The path
is gleaned from the SCRIPT_NAME
environment variable, and secure
is false.
*value
value or list of values of the cookie
options_hash
A Hash
of options to initialize this Cookie
. Possible options are:
the name of the cookie. Required.
the cookie’s value or list of values.
the path for which this cookie applies. Defaults to the value of the SCRIPT_NAME
environment variable.
the domain for which this cookie applies.
the time at which this cookie expires, as a Time
object.
whether this cookie is a secure cookie or not (default to false). Secure cookies are only transmitted to HTTPS servers.
whether this cookie is a HttpOnly cookie or not (default to
false). HttpOnly cookies are not available to javascript.
These keywords correspond to attributes of the cookie object.
Create a new CGI::Session
object for request
.
request
is an instance of the CGI
class (see cgi.rb). option
is a hash of options for initialising this CGI::Session
instance. The following options are recognised:
the parameter name used for the session id. Defaults to ‘_session_id’.
session_id
the session id to use. If not provided, then it is retrieved from the session_key
parameter of the request, or automatically generated for a new session.
new_session
if true, force creation of a new session. If not set, a new session is only created if none currently exists. If false, a new session is never created, and if none currently exists and the session_id
option is not set, an ArgumentError
is raised.
the name of the class providing storage facilities for session state persistence. Built-in support is provided for FileStore
(the default), MemoryStore
, and PStore
(from cgi/session/pstore.rb). See the documentation for these classes for more details.
The following options are also recognised, but only apply if the session id is stored in a cookie.
the time the current session expires, as a Time
object. If not set, the session will terminate when the user’s browser is closed.
the hostname domain for which this session is valid. If not set, defaults to the hostname of the server.
if true
, this session will only work over HTTPS.
the path for which this session applies. Defaults to the directory of the CGI
script.
option
is also passed on to the session storage class initializer; see the documentation for each session storage class for the options they support.
The retrieved or created session is automatically added to request
as a cookie, and also to its output_hidden
table, which is used to add hidden input elements to forms.
WARNING the output_hidden
fields are surrounded by a <fieldset> tag in HTML 4 generation, which is not invisible on many browsers; you may wish to disable the use of fieldsets with code similar to the following (see blade.ruby-lang.org/ruby-list/37805)
cgi = CGI.new("html4") class << cgi undef_method :fieldset end
A CSV::FieldsConverter
is a data structure for storing the fields converter properties to be passed as a parameter when parsing a new file (e.g. CSV::Parser.new
(@io, parser_options))
Returns the new CSV::Row instance constructed from arguments headers
and fields
; both should be Arrays; note that the fields need not be Strings:
row = CSV::Row.new(['Name', 'Value'], ['foo', 0]) row # => #<CSV::Row "Name":"foo" "Value":0>
If the Array lengths are different, the shorter is nil
-filled:
row = CSV::Row.new(['Name', 'Value', 'Date', 'Size'], ['foo', 0]) row # => #<CSV::Row "Name":"foo" "Value":0 "Date":nil "Size":nil>
Each CSV::Row object is either a field row or a header row; by default, a new row is a field row; for the row created above:
row.field_row? # => true row.header_row? # => false
If the optional argument header_row
is given as true
, the created row is a header row:
row = CSV::Row.new(['Name', 'Value'], ['foo', 0], header_row = true) row # => #<CSV::Row "Name":"foo" "Value":0> row.field_row? # => false row.header_row? # => true
Returns a new CSV::Table object.
Argument array_of_rows
must be an Array of CSV::Row
objects.
Argument headers
, if given, may be an Array of Strings.
Create an empty CSV::Table object:
table = CSV::Table.new([]) table # => #<CSV::Table mode:col_or_row row_count:1>
Create a non-empty CSV::Table object:
rows = [ CSV::Row.new([], []), CSV::Row.new([], []), CSV::Row.new([], []), ] table = CSV::Table.new(rows) table # => #<CSV::Table mode:col_or_row row_count:4>
If argument headers
is an Array of Strings, those Strings become the table’s headers:
table = CSV::Table.new([], headers: ['Name', 'Age']) table.headers # => ["Name", "Age"]
If argument headers
is not given and the table has rows, the headers are taken from the first row:
rows = [ CSV::Row.new(['Foo', 'Bar'], []), CSV::Row.new(['foo', 'bar'], []), CSV::Row.new(['FOO', 'BAR'], []), ] table = CSV::Table.new(rows) table.headers # => ["Foo", "Bar"]
If argument headers
is not given and the table is empty (has no rows), the headers are also empty:
table = CSV::Table.new([]) table.headers # => []
Raises an exception if argument array_of_rows
is not an Array object:
# Raises NoMethodError (undefined method `first' for :foo:Symbol): CSV::Table.new(:foo)
Raises an exception if an element of array_of_rows
is not a CSV::Table object:
# Raises NoMethodError (undefined method `headers' for :foo:Symbol): CSV::Table.new([:foo])