Returns the string being scanned.
Changes the string being scanned to str
and resets the scanner. Returns str
.
Returns the byte position of the scan pointer. In the ‘reset’ position, this value is zero. In the ‘terminated’ position (i.e. the string is exhausted), this value is the bytesize of the string.
In short, it’s a 0-based index into bytes of the string.
s = StringScanner.new('test string') s.pos # -> 0 s.scan_until /str/ # -> "test str" s.pos # -> 8 s.terminate # -> #<StringScanner fin> s.pos # -> 11
Set
the byte position of the scan pointer.
s = StringScanner.new('test string') s.pos = 7 # -> 7 s.rest # -> "ring"
Tests whether the given pattern
is matched from the current scan pointer. Returns the length of the match, or nil
. The scan pointer is not advanced.
s = StringScanner.new('test string') p s.match?(/\w+/) # -> 4 p s.match?(/\w+/) # -> 4 p s.match?(/\s+/) # -> nil
Returns true
iff the last match was successful.
s = StringScanner.new('test string') s.match?(/\w+/) # => 4 s.matched? # => true s.match?(/\d+/) # => nil s.matched? # => false
Returns the last matched string.
s = StringScanner.new('test string') s.match?(/\w+/) # -> 4 s.matched # -> "test"
Returns a string that represents the StringScanner
object, showing:
the current position
the size of the string
the characters surrounding the scan pointer
s = StringScanner.new
(“Fri Dec 12 1975 14:39”) s.inspect # -> ‘#<StringScanner 0/21 @ “Fri D…”>’ s.scan_until /12/ # -> “Fri Dec 12” s.inspect # -> ‘#<StringScanner 10/21 “…ec 12” @ “ 1975…”>’
Runs OLE method. The first argument specifies the method name of OLE Automation object. The others specify argument of the method. If you can not execute method directly, then use this method instead.
excel = WIN32OLE.new('Excel.Application') excel.invoke('Quit') # => same as excel.Quit
Runs the early binding method. The 1st argument specifies dispatch ID, the 2nd argument specifies the array of arguments, the 3rd argument specifies the array of the type of arguments.
excel = WIN32OLE.new('Excel.Application') excel._invoke(302, [], []) # same effect as excel.Quit
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 the method name with class name.
Returns true if the parameter is input.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbook') method = WIN32OLE_METHOD.new(tobj, 'SaveAs') param1 = method.params[0] puts param1.input? # => true
Returns the parameter name with class name. If the parameter has default value, then returns name=value string with class name.
Returns the OLE struct name and member name and the value of member
If COM server in VB.NET ComServer project is the following:
Imports System.Runtime.InteropServices Public Class ComClass <MarshalAs(UnmanagedType.BStr)> _ Public title As String Public cost As Integer End Class
then
srver = WIN32OLE.new('ComServer.ComClass') obj = WIN32OLE_RECORD.new('Book', server) obj.inspect # => <WIN32OLE_RECORD(ComClass) {"title" => nil, "cost" => nil}>
Returns number which represents type.
tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents') puts tobj.typekind # => 4
Returns help string.
tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', 'IWebBrowser') puts tobj.helpstring # => Web Browser interface
Returns the type name with class name.
ie = WIN32OLE.new('InternetExplorer.Application') ie.ole_type.inspect => #<WIN32OLE_TYPE:IWebBrowser2>
Returns the type library name with class name.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') tlib.inspect # => "<#WIN32OLE_TYPELIB:Microsoft Excel 9.0 Object Library>"
Returns the number which represents variable kind.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'XlSheetType') variables = tobj.variables variables.each do |variable| puts "#{variable.name} #{variable.varkind}" end The result of above script is following: xlChart 2 xlDialogSheet 2 xlExcel4IntlMacroSheet 2 xlExcel4MacroSheet 2 xlWorksheet 2
Returns the OLE variable name and the value with class name.
Return the contents of this hash as a string.
h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 } h.to_s #=> "{\"c\"=>300, \"a\"=>100, \"d\"=>400}"
Returns a new hash created by using hsh’s values as keys, and the keys as values. If a key with the same value already exists in the hsh, then the last one defined will be used, the earlier value(s) will be discarded.
h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 } h.invert #=> {0=>"a", 100=>"m", 200=>"d", 300=>"y"}
If there is no key with the same value, Hash#invert
is involutive.
h = { a: 1, b: 3, c: 4 } h.invert.invert == h #=> true
The condition, no key with the same value, can be tested by comparing the size of inverted hash.
# no key with the same value h = { a: 1, b: 3, c: 4 } h.size == h.invert.size #=> true # two (or more) keys has the same value h = { a: 1, b: 3, c: 1 } h.size == h.invert.size #=> false
Returns true
if the given key is present in hsh.
h = { "a" => 100, "b" => 200 } h.has_key?("a") #=> true h.has_key?("z") #=> false
Note that include?
and member?
do not test member equality using ==
as do other Enumerables.
See also Enumerable#include?
Returns a new hash created by using environment variable names as values and values as names.