By overriding Object#methods
, WIN32OLE
might work well with did_you_mean gem. This is experimental.
require 'win32ole' dict = WIN32OLE.new('Scripting.Dictionary') dict.Ade('a', 1) #=> Did you mean? Add
Sets current codepage. The WIN32OLE.codepage
is initialized according to Encoding.default_internal
. If Encoding.default_internal
is nil then WIN32OLE.codepage
is initialized according to Encoding.default_external
.
WIN32OLE.codepage = WIN32OLE::CP_UTF8 WIN32OLE.codepage = 65001
Returns current locale id (lcid). The default locale is WIN32OLE::LOCALE_SYSTEM_DEFAULT
.
lcid = WIN32OLE.locale
Sets current locale id (lcid).
WIN32OLE.locale = 1033 # set locale English(U.S) obj = WIN32OLE_VARIANT.new("$100,000", WIN32OLE::VARIANT::VT_CY)
sets event handler object. If handler object has onXXX method according to XXX event, then onXXX method is called when XXX event occurs.
If handler object has method_missing and there is no method according to the event, then method_missing called and 1-st argument is event name.
If handler object has onXXX method and there is block defined by WIN32OLE_EVENT#on_event
(‘XXX’){}, then block is executed but handler object method is not called when XXX event occurs.
class Handler def onStatusTextChange(text) puts "StatusTextChanged" end def onPropertyChange(prop) puts "PropertyChanged" end def method_missing(ev, *arg) puts "other event #{ev}" end end handler = Handler.new ie = WIN32OLE.new('InternetExplorer.Application') ev = WIN32OLE_EVENT.new(ie) ev.on_event("StatusTextChange") {|*args| puts "this block executed." puts "handler.onStatusTextChange method is not called." } ev.handler = handler
returns handler object.
Returns true if the method is public.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbooks') method = WIN32OLE_METHOD.new(tobj, 'Add') puts method.visible? # => true
Returns help file. If help file is not found, then the method returns nil.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbooks') method = WIN32OLE_METHOD.new(tobj, 'Add') puts method.helpfile # => C:\...\VBAXL9.CHM
Returns default value. If the default value does not exist, this method returns nil.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Workbook') method = WIN32OLE_METHOD.new(tobj, 'SaveAs') method.params.each do |param| if param.default puts "#{param.name} (= #{param.default})" else puts "#{param}" end end The above script result is following: Filename FileFormat Password WriteResPassword ReadOnlyRecommended CreateBackup AccessMode (= 1) ConflictResolution AddToMru TextCodepage TextVisualLayout
Returns true if the OLE class is public.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application') puts tobj.visible # => true
Returns helpfile path. If helpfile is not found, then returns nil.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Worksheet') puts tobj.helpfile # => C:\...\VBAXL9.CHM
Returns array of WIN32OLE_VARIABLE
objects which represent variables defined in OLE class.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'XlSheetType') vars = tobj.variables vars.each do |v| puts "#{v.name} = #{v.value}" end The result of above sample script is follows: xlChart = -4109 xlDialogSheet = -4116 xlExcel4IntlMacroSheet = 4 xlExcel4MacroSheet = 3 xlWorksheet = -4167
Returns true if the type library information is not hidden. If wLibFlags of TLIBATTR is 0 or LIBFLAG_FRESTRICTED or LIBFLAG_FHIDDEN, the method returns false, otherwise, returns true. If the method fails to access the TLIBATTR information, then WIN32OLERuntimeError
is raised.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') tlib.visible? # => true
Returns true if the variable is public.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'XlSheetType') variables = tobj.variables variables.each do |variable| puts "#{variable.name} #{variable.visible?}" end The result of above script is following: xlChart true xlDialogSheet true xlExcel4IntlMacroSheet true xlExcel4MacroSheet true xlWorksheet true
Returns the default value, the value that would be returned by hsh[key] if key did not exist in hsh. See also Hash::new
and Hash#default=
.
h = Hash.new #=> {} h.default #=> nil h.default(2) #=> nil h = Hash.new("cat") #=> {} h.default #=> "cat" h.default(2) #=> "cat" h = Hash.new {|h,k| h[k] = k.to_i*10} #=> {} h.default #=> nil h.default(2) #=> 20
Sets the default value, the value returned for a key that does not exist in the hash. It is not possible to set the default to a Proc
that will be executed on each key lookup.
h = { "a" => 100, "b" => 200 } h.default = "Go fish" h["a"] #=> 100 h["z"] #=> "Go fish" # This doesn't do what you might hope... h.default = proc do |hash, key| hash[key] = key + key end h[2] #=> #<Proc:0x401b3948@-:6> h["cat"] #=> #<Proc:0x401b3948@-:6>
Returns the number of key-value pairs in the hash.
h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 } h.size #=> 4 h.delete("a") #=> 200 h.size #=> 3 h.length #=> 3
Hash#length
is an alias for Hash#size
.
Deletes the key-value pair and returns the value from hsh whose key is equal to key. If the key is not found, it returns nil. If the optional code block is given and the key is not found, pass in the key and return the result of block.
h = { "a" => 100, "b" => 200 } h.delete("a") #=> 100 h.delete("z") #=> nil h.delete("z") { |el| "#{el} not found" } #=> "z not found"
Removes all key-value pairs from hsh.
h = { "a" => 100, "b" => 200 } #=> {"a"=>100, "b"=>200} h.clear #=> {}
Deletes the environment variable with name
if it exists and returns its value:
ENV['foo'] = '0' ENV.delete('foo') # => '0'
Returns nil
if the named environment variable does not exist:
ENV.delete('foo') # => nil
If a block given and the environment variable does not exist, yields name
to the block and returns nil
:
ENV.delete('foo') { |name| puts name } # => nil foo
If a block given and the environment variable exists, deletes the environment variable and returns its value (ignoring the block):
ENV['foo'] = '0' ENV.delete('foo') { |name| fail 'ignored' } # => "0"
Raises an exception if name
is invalid. See Invalid Names and Values.
Removes every environment variable; returns ENV:
ENV.replace('foo' => '0', 'bar' => '1') ENV.size # => 2 ENV.clear # => ENV ENV.size # => 0
Returns the number of environment variables.
Returns an integer representing the numeric file descriptor for the current file. Raises an ArgumentError
if there isn’t a current file.
ARGF.fileno #=> 3
This is a deprecated alias for each_codepoint
.