Returns true
if strio is not writable, false
otherwise.
This method is defined for backward compatibility.
Advances the scan pointer until pattern
is matched and consumed. Returns the number of bytes advanced, or nil
if no match was found.
Look ahead to match pattern
, and advance the scan pointer to the end of the match. Return the number of characters advanced, or nil
if the match was unsuccessful.
It’s similar to scan_until
, but without returning the intervening string.
s = StringScanner.new("Fri Dec 12 1975 14:39") s.skip_until /12/ # -> 10 s #
Returns the post-match
(in the regular expression sense) of the last scan.s = StringScanner.new('test string') s.scan(/\w+/) # -> "test" s.scan(/\s+/) # -> " " s.pre_match # -> "test" s.post_match # -> "string"
s.rest_size
is equivalent to s.rest.size
.
Defines the constants of OLE Automation server as mod’s constants. The first argument is WIN32OLE
object or type library name. If 2nd argument is omitted, the default is WIN32OLE
. The first letter of Ruby’s constant variable name is upper case, so constant variable name of WIN32OLE
object is capitalized. For example, the ‘xlTop’ constant of Excel is changed to ‘XlTop’ in WIN32OLE
. If the first letter of constant variable is not [A-Z], then the constant is defined as CONSTANTS hash element.
module EXCEL_CONST end excel = WIN32OLE.new('Excel.Application') WIN32OLE.const_load(excel, EXCEL_CONST) puts EXCEL_CONST::XlTop # => -4160 puts EXCEL_CONST::CONSTANTS['_xlDialogChartSourceData'] # => 541 WIN32OLE.const_load(excel) puts WIN32OLE::XlTop # => -4160 module MSO end WIN32OLE.const_load('Microsoft Office 9.0 Object Library', MSO) puts MSO::MsoLineSingle # => 1
Returns variable kind string.
tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'XlSheetType') variables = tobj.variables variables.each do |variable| puts "#{variable.name} #{variable.variable_kind}" end The result of above script is following: xlChart CONSTANT xlDialogSheet CONSTANT xlExcel4IntlMacroSheet CONSTANT xlExcel4MacroSheet CONSTANT xlWorksheet CONSTANT
Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (obj). In order to set the context, the variable self
is set to obj while the code is executing, giving the code access to obj’s instance variables and private methods.
When instance_eval
is given a block, obj is also passed in as the block’s only argument.
When instance_eval
is given a String
, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors.
class KlassWithSecret def initialize @secret = 99 end private def the_secret "Ssssh! The secret is #{@secret}." end end k = KlassWithSecret.new k.instance_eval { @secret } #=> 99 k.instance_eval { the_secret } #=> "Ssssh! The secret is 99." k.instance_eval {|obj| obj == self } #=> true
Executes the given block within the context of the receiver (obj). In order to set the context, the variable self
is set to obj while the code is executing, giving the code access to obj’s instance variables. Arguments are passed as block parameters.
class KlassWithSecret def initialize @secret = 99 end end k = KlassWithSecret.new k.instance_exec(5) {|x| @secret+x } #=> 104
Try to convert obj into a hash, using to_hash
method. Returns converted hash or nil if obj cannot be converted for any reason.
Hash.try_convert({1=>2}) # => {1=>2} Hash.try_convert("1=>2") # => nil
Returns a new hash with the results of running the block once for every key. This method does not change the values.
h = { a: 1, b: 2, c: 3 } h.transform_keys {|k| k.to_s } #=> { "a" => 1, "b" => 2, "c" => 3 } h.transform_keys(&:to_s) #=> { "a" => 1, "b" => 2, "c" => 3 } h.transform_keys.with_index {|k, i| "#{k}.#{i}" } #=> { "a.0" => 1, "b.1" => 2, "c.2" => 3 }
If no block is given, an enumerator is returned instead.
Invokes the given block once for each key in hsh, replacing it with the new key returned by the block, and then returns hsh. This method does not change the values.
h = { a: 1, b: 2, c: 3 } h.transform_keys! {|k| k.to_s } #=> { "a" => 1, "b" => 2, "c" => 3 } h.transform_keys!(&:to_sym) #=> { a: 1, b: 2, c: 3 } h.transform_keys!.with_index {|k, i| "#{k}.#{i}" } #=> { "a.0" => 1, "b.1" => 2, "c.2" => 3 }
If no block is given, an enumerator is returned instead.
Returns a new hash with the results of running the block once for every value. This method does not change the keys.
h = { a: 1, b: 2, c: 3 } h.transform_values {|v| v * v + 1 } #=> { a: 2, b: 5, c: 10 } h.transform_values(&:to_s) #=> { a: "1", b: "2", c: "3" } h.transform_values.with_index {|v, i| "#{v}.#{i}" } #=> { a: "1.0", b: "2.1", c: "3.2" }
If no block is given, an enumerator is returned instead.
Invokes the given block once for each value in hsh, replacing it with the new value returned by the block, and then returns hsh. This method does not change the keys.
h = { a: 1, b: 2, c: 3 } h.transform_values! {|v| v * v + 1 } #=> { a: 2, b: 5, c: 10 } h.transform_values!(&:to_s) #=> { a: "2", b: "5", c: "10" } h.transform_values!.with_index {|v, i| "#{v}.#{i}" } #=> { a: "2.0", b: "5.1", c: "10.2" }
If no block is given, an enumerator is returned instead.
Returns true
if headers are written in output. See CSV::new
for details.
Returns true
blank lines are skipped by the parser. See CSV::new
for details.
Returns true if the ipaddr is an IPv4-mapped IPv6 address.
Returns true if the ipaddr is an IPv4-compatible IPv6 address.
Returns a new ipaddr built by converting the native IPv4 address into an IPv4-mapped IPv6 address.
Returns a new ipaddr built by converting the native IPv4 address into an IPv4-compatible IPv6 address.
Returns a string for DNS reverse lookup compatible with RFC3172.
Returns a string for DNS reverse lookup compatible with RFC1886.