Returns Ruby Hash
object which represents VT_RECORD variable. The keys of Hash
object are member names of VT_RECORD OLE variable and the values of Hash
object are values of VT_RECORD OLE variable.
If COM server in VB.NET ComServer project is the following:
Imports System.Runtime.InteropServices Public Class ComClass Public Structure Book <MarshalAs(UnmanagedType.BStr)> _ Public title As String Public cost As Integer End Structure Public Function getBook() As Book Dim book As New Book book.title = "The Ruby Book" book.cost = 20 Return book End Function End Class
then, the result of WIN32OLE::Record#to_h
is the following:
require 'win32ole' obj = WIN32OLE.new('ComServer.ComClass') book = obj.getBook book.to_h # => {"title"=>"The Ruby Book", "cost"=>20}
Returns OLE type name.
tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Application') puts tobj.name # => Application
Returns the type library name.
tlib = WIN32OLE::TypeLib.new('Microsoft Excel 9.0 Object Library') name = tlib.name # -> 'Microsoft Excel 9.0 Object Library'
Returns the name of variable.
tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'XlSheetType') variables = tobj.variables variables.each do |variable| puts "#{variable.name}" end The result of above script is following: xlChart xlDialogSheet xlExcel4IntlMacroSheet xlExcel4MacroSheet xlWorksheet
Resets and initializes the stream. All data in both input and output buffer are discarded.
Resets the position of the file pointer to the point created the GzipReader
object. The associated IO
object needs to respond to the seek
method.
See Zlib::GzipReader
documentation for a description.
Reads at most maxlen bytes from the gzipped stream but it blocks only if gzipreader has no data immediately available. If the optional outbuf argument is present, it must reference a String
, which will receive the data. It raises EOFError
on end of file.
See Zlib::GzipReader
documentation for a description.
See Zlib::GzipReader
documentation for a description.
See Zlib::GzipReader
documentation for a description.
See Zlib::GzipReader
documentation for a description.
Returns true
if stat is readable by the effective user id of this process.
File.stat("testfile").readable? #=> true
Returns true
if stat has its sticky bit set, false
if it doesn’t or if the operating system doesn’t support this feature.
File.stat("testfile").sticky? #=> false
Creates a zero-copy IO::Buffer
from the given string’s memory. Without a block a frozen internal copy of the string is created efficiently and used as the buffer source. When a block is provided, the buffer is associated directly with the string’s internal buffer and updating the buffer will update the string.
Until free
is invoked on the buffer, either explicitly or via the garbage collector, the source string will be locked and cannot be modified.
If the string is frozen, it will create a read-only buffer which cannot be modified. If the string is shared, it may trigger a copy-on-write when using the block form.
string = 'test' buffer = IO::Buffer.for(string) buffer.external? #=> true buffer.get_string(0, 1) # => "t" string # => "best" buffer.resize(100) # in `resize': Cannot resize external buffer! (IO::Buffer::AccessError) IO::Buffer.for(string) do |buffer| buffer.set_string("T") string # => "Test" end
Creates a new string of the given length and yields a zero-copy IO::Buffer
instance to the block which uses the string as a source. The block is expected to write to the buffer and the string will be returned.
IO::Buffer.string(4) do |buffer| buffer.set_string("Ruby") end # => "Ruby"
Short representation of the buffer. It includes the address, size and symbolic flags. This format is subject to change.
puts IO::Buffer.new(4) # uses to_s internally # #<IO::Buffer 0x000055769f41b1a0+4 INTERNAL>
If the buffer is shared, meaning it references memory that can be shared with other processes (and thus might change without being modified locally).
# Create a test file: File.write('test.txt', 'test') # Create a shared mapping from the given file, the file must be opened in # read-write mode unless we also specify IO::Buffer::READONLY: buffer = IO::Buffer.map(File.open('test.txt', 'r+'), nil, 0) # => #<IO::Buffer 0x00007f1bffd5e000+4 EXTERNAL MAPPED SHARED> # Write to the buffer, which will modify the mapped file: buffer.set_string('b', 0) # => 1 # The file itself is modified: File.read('test.txt') # => "best"
If the buffer is read only, meaning the buffer cannot be modified using set_value
, set_string
or copy
and similar.
Frozen strings and read-only files create read-only buffers.
Resizes a buffer to a new_size
bytes, preserving its content. Depending on the old and new size, the memory area associated with the buffer might be either extended, or rellocated at different address with content being copied.
buffer = IO::Buffer.new(4) buffer.set_string("test", 0) buffer.resize(8) # resize to 8 bytes # => # #<IO::Buffer 0x0000555f5d1a1630+8 INTERNAL> # 0x00000000 74 65 73 74 00 00 00 00 test....
External buffer (created with ::for
), and locked buffer can not be resized.
If the buffer references memory, release it back to the operating system.
for a mapped buffer (e.g. from file): unmap.
for a buffer created from scratch: free memory.
for a buffer created from string: undo the association.
After the buffer is freed, no further operations can’t be performed on it.
You can resize a freed buffer to re-allocate it.
buffer = IO::Buffer.for('test') buffer.free # => #<IO::Buffer 0x0000000000000000+0 NULL> buffer.get_value(:U8, 0) # in `get_value': The buffer is not allocated! (IO::Buffer::AllocationError) buffer.get_string # in `get_string': The buffer is not allocated! (IO::Buffer::AllocationError) buffer.null? # => true
Modify the source buffer in place by applying the binary OR operation to the source, using the mask, repeating as necessary.
source = IO::Buffer.for("1234567890").dup # Make a read/write copy. # => # #<IO::Buffer 0x000056307a272350+10 INTERNAL> # 0x00000000 31 32 33 34 35 36 37 38 39 30 1234567890 source.or!(IO::Buffer.for("\xFF\x00\x00\xFF")) # => # #<IO::Buffer 0x000056307a272350+10 INTERNAL> # 0x00000000 ff 32 33 ff ff 36 37 ff ff 30 .23..67..0
Modify the source buffer in place by applying the binary XOR operation to the source, using the mask, repeating as necessary.
source = IO::Buffer.for("1234567890").dup # Make a read/write copy. # => # #<IO::Buffer 0x000056307a25b3e0+10 INTERNAL> # 0x00000000 31 32 33 34 35 36 37 38 39 30 1234567890 source.xor!(IO::Buffer.for("\xFF\x00\x00\xFF")) # => # #<IO::Buffer 0x000056307a25b3e0+10 INTERNAL> # 0x00000000 ce 32 33 cb ca 36 37 c7 c6 30 .23..67..0
Read at least length
bytes from the io
, into the buffer starting at offset
. If an error occurs, return -errno
.
If length
is not given or nil
, it defaults to the size of the buffer minus the offset, i.e. the entire buffer.
If length
is zero, exactly one read
operation will occur.
If offset
is not given, it defaults to zero, i.e. the beginning of the buffer.
IO::Buffer.for('test') do |buffer| p buffer # => # <IO::Buffer 0x00007fca40087c38+4 SLICE> # 0x00000000 74 65 73 74 test buffer.read(File.open('/dev/urandom', 'rb'), 2) p buffer # => # <IO::Buffer 0x00007f3bc65f2a58+4 EXTERNAL SLICE> # 0x00000000 05 35 73 74 .5st end
Read at least length
bytes from the io
starting at the specified from
position, into the buffer starting at offset
. If an error occurs, return -errno
.
If length
is not given or nil
, it defaults to the size of the buffer minus the offset, i.e. the entire buffer.
If length
is zero, exactly one pread
operation will occur.
If offset
is not given, it defaults to zero, i.e. the beginning of the buffer.
IO::Buffer.for('test') do |buffer| p buffer # => # <IO::Buffer 0x00007fca40087c38+4 SLICE> # 0x00000000 74 65 73 74 test # take 2 bytes from the beginning of urandom, # put them in buffer starting from position 2 buffer.pread(File.open('/dev/urandom', 'rb'), 0, 2, 2) p buffer # => # <IO::Buffer 0x00007f3bc65f2a58+4 EXTERNAL SLICE> # 0x00000000 05 35 73 74 te.5 end