Scans one character and returns it. This method is multibyte character sensitive.
s = StringScanner.new("ab") s.getch # => "a" s.getch # => "b" s.getch # => nil s = StringScanner.new("\244\242".force_encoding("euc-jp")) s.getch # => "\x{A4A2}" # Japanese hira-kana "A" in EUC-JP s.getch # => nil
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)
Runs the early binding method to set property. 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._setproperty(558, [true], [WIN32OLE::VARIANT::VT_BOOL]) # same effect as excel.visible = true
Sets property of OLE object. When you want to set property with argument, you can use this method.
excel = WIN32OLE.new('Excel.Application') excel.Visible = true book = excel.workbooks.add sheet = book.worksheets(1) sheet.setproperty('Cells', 1, 2, 10) # => The B1 cell value is 10.
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 array of ProgID.
Returns ProgID if it exists. If not found, then returns nil.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application') puts tobj.progid # => Excel.Application.9
Returns the type library version.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') puts tlib.version #-> "1.3"
Hash#filter
is an alias for Hash#select
.
Returns a new Hash object whose entries are those for which the block returns a truthy value:
h = {foo: 0, bar: 1, baz: 2} h.select {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
Returns a new Enumerator if no block given:
h = {foo: 0, bar: 1, baz: 2} e = h.select # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:select> e.each {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
Hash#filter!
is an alias for Hash#select!
.
Returns self
, whose entries are those for which the block returns a truthy value:
h = {foo: 0, bar: 1, baz: 2} h.select! {|key, value| value < 2 } => {:foo=>0, :bar=>1}
Returns nil
if no entries were removed.
Returns a new Enumerator if no block given:
h = {foo: 0, bar: 1, baz: 2} e = h.select! # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:select!> e.each { |key, value| value < 2 } # => {:foo=>0, :bar=>1}
Returns a new Hash object with the each key-value pair inverted:
h = {foo: 0, bar: 1, baz: 2} h1 = h.invert h1 # => {0=>:foo, 1=>:bar, 2=>:baz}
Overwrites any repeated new keys: (see Entry Order):
h = {foo: 0, bar: 0, baz: 0} h.invert # => {0=>:baz}
Methods has_key?
, key?
, and member?
are aliases for #include?.
Returns true
if key
is a key in self
, otherwise false
.
ENV.filter
is an alias for ENV.select
.
Yields each environment variable name and its value as a 2-element Array
, returning a Hash
of the names and values for which the block returns a truthy value:
ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') ENV.select { |name, value| name.start_with?('b') } # => {"bar"=>"1", "baz"=>"2"} ENV.filter { |name, value| name.start_with?('b') } # => {"bar"=>"1", "baz"=>"2"}
Returns an Enumerator
if no block given:
e = ENV.select # => #<Enumerator: {"bar"=>"1", "baz"=>"2", "foo"=>"0"}:select> e.each { |name, value | name.start_with?('b') } # => {"bar"=>"1", "baz"=>"2"} e = ENV.filter # => #<Enumerator: {"bar"=>"1", "baz"=>"2", "foo"=>"0"}:filter> e.each { |name, value | name.start_with?('b') } # => {"bar"=>"1", "baz"=>"2"}
ENV.filter!
is an alias for ENV.select!
.
Yields each environment variable name and its value as a 2-element Array
, deleting each entry for which the block returns false
or nil
, and returning ENV
if any deletions made, or nil
otherwise:
ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') ENV.select! { |name, value| name.start_with?('b') } # => ENV ENV # => {"bar"=>"1", "baz"=>"2"} ENV.select! { |name, value| true } # => nil ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') ENV.filter! { |name, value| name.start_with?('b') } # => ENV ENV # => {"bar"=>"1", "baz"=>"2"} ENV.filter! { |name, value| true } # => nil
Returns an Enumerator
if no block given:
ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') e = ENV.select! # => #<Enumerator: {"bar"=>"1", "baz"=>"2"}:select!> e.each { |name, value| name.start_with?('b') } # => ENV ENV # => {"bar"=>"1", "baz"=>"2"} e.each { |name, value| true } # => nil ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') e = ENV.filter! # => #<Enumerator: {"bar"=>"1", "baz"=>"2"}:filter!> e.each { |name, value| name.start_with?('b') } # => ENV ENV # => {"bar"=>"1", "baz"=>"2"} e.each { |name, value| true } # => nil
Returns a Hash
whose keys are the ENV
values, and whose values are the corresponding ENV
names:
ENV.replace('foo' => '0', 'bar' => '1') ENV.invert # => {"1"=>"bar", "0"=>"foo"}
For a duplicate ENV
value, overwrites the hash entry:
ENV.replace('foo' => '0', 'bar' => '0') ENV.invert # => {"0"=>"foo"}
Note that the order of the ENV
processing is OS-dependent, which means that the order of overwriting is also OS-dependent. See About Ordering.
ENV.has_key?
, ENV.member?
, and ENV.key?
are aliases for ENV.include?
.
Returns true
if there is an environment variable with the given name
:
ENV.replace('foo' => '0', 'bar' => '1') ENV.include?('foo') # => true
Returns false
if name
is a valid String
and there is no such environment variable:
ENV.include?('baz') # => false
Returns false
if name
is the empty String
or is a String
containing character '='
:
ENV.include?('') # => false ENV.include?('=') # => false
Raises an exception if name
is a String
containing the NUL character "\0"
:
ENV.include?("\0") # Raises ArgumentError (bad environment variable name: contains null byte)
Raises an exception if name
has an encoding that is not ASCII-compatible:
ENV.include?("\xa1\xa1".force_encoding(Encoding::UTF_16LE)) # Raises ArgumentError (bad environment variable name: ASCII incompatible encoding: UTF-16LE)
Raises an exception if name
is not a String:
ENV.include?(Object.new) # TypeError (no implicit conversion of Object into String)
Returns ENV
itself, and warns because ENV
is a wrapper for the process-wide environment variables and a clone is useless. If freeze
keyword is given and not nil
or false
, raises ArgumentError
. If freeze
keyword is given and true
, raises TypeError
, as ENV
storage cannot be frozen.
Returns the next line from the current file in ARGF
.
By default lines are assumed to be separated by $/
; to use a different character as a separator, supply it as a String
for the sep argument.
The optional limit argument specifies how many characters of each line to return. By default all characters are returned.
See IO.readlines
for details about getline_args.
Reads the next character from ARGF
and returns it as a String
. Returns nil
at the end of the stream.
ARGF
treats the files named on the command line as a single file created by concatenating their contents. After returning the last character of the first file, it returns the first character of the second file, and so on.
For example:
$ echo "foo" > file $ ruby argf.rb file ARGF.getc #=> "f" ARGF.getc #=> "o" ARGF.getc #=> "o" ARGF.getc #=> "\n" ARGF.getc #=> nil ARGF.getc #=> nil
Gets the next 8-bit byte (0..255) from ARGF
. Returns nil
if called at the end of the stream.
For example:
$ echo "foo" > file $ ruby argf.rb file ARGF.getbyte #=> 102 ARGF.getbyte #=> 111 ARGF.getbyte #=> 111 ARGF.getbyte #=> 10 ARGF.getbyte #=> nil