Results for: "String#[]"

No documentation available
No documentation available

Write value to a registry value named name.

If wtype is specified, the value type is it. Otherwise, the value type is depend on class of value: :Integer

REG_DWORD

:String

REG_SZ

:Array

REG_MULTI_SZ

Creates a weak reference from the given key to the given value

Set the session data for key key.

Assigns the field value for the given index or header; returns value.


Assign field value by Integer index:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
row = table[0]
row[0] = 'Bat'
row[1] = 3
row # => #<CSV::Row "Name":"Bat" "Value":3>

Counts backward from the last column if index is negative:

row[-1] = 4
row[-2] = 'Bam'
row # => #<CSV::Row "Name":"Bam" "Value":4>

Extends the row with nil:nil if positive index is not in the row:

row[4] = 5
row # => #<CSV::Row "Name":"bad" "Value":4 nil:nil nil:nil nil:5>

Raises IndexError if negative index is too small (too far from zero).


Assign field value by header (first found):

source = "Name,Name,Name\nFoo,Bar,Baz\n"
table = CSV.parse(source, headers: true)
row = table[0]
row['Name'] = 'Bat'
row # => #<CSV::Row "Name":"Bat" "Name":"Bar" "Name":"Baz">

Assign field value by header, ignoring offset leading fields:

source = "Name,Name,Name\nFoo,Bar,Baz\n"
table = CSV.parse(source, headers: true)
row = table[0]
row['Name', 2] = 4
row # => #<CSV::Row "Name":"Foo" "Name":"Bar" "Name":4>

Append new field by (new) header:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
row = table[0]
row['New'] = 6
row# => #<CSV::Row "Name":"foo" "Value":"0" "New":6>

Puts data onto the table.


Set a Row by Its Integer Index

If the row exists, it is replaced:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
new_row = CSV::Row.new(['Name', 'Value'], ['bat', 3])
table.by_row! # => #<CSV::Table mode:row row_count:4>
return_value = table[0] = new_row
return_value.equal?(new_row) # => true # Returned the row
table[0].to_h # => {"Name"=>"bat", "Value"=>3}

With access mode :col_or_row:

table.by_col_or_row! # => #<CSV::Table mode:col_or_row row_count:4>
table[0] = CSV::Row.new(['Name', 'Value'], ['bam', 4])
table[0].to_h # => {"Name"=>"bam", "Value"=>4}

With an Array instead of a CSV::Row, inherits headers from the table:

array = ['bad', 5]
return_value = table[0] = array
return_value.equal?(array) # => true # Returned the array
table[0].to_h # => {"Name"=>"bad", "Value"=>5}

If the row does not exist, extends the table by adding rows: assigns rows with nil as needed:

table.size # => 3
table[5] = ['bag', 6]
table.size # => 6
table[3] # => nil
table[4]# => nil
table[5].to_h # => {"Name"=>"bag", "Value"=>6}

Note that the nil rows are actually nil, not a row of nil fields.


Set a Column by Its Integer Index

If the column exists, it is replaced:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
new_col = [3, 4, 5]
table.by_col! # => #<CSV::Table mode:col row_count:4>
return_value = table[1] = new_col
return_value.equal?(new_col) # => true # Returned the column
table[1] # => [3, 4, 5]
# The rows, as revised:
table.by_row! # => #<CSV::Table mode:row row_count:4>
table[0].to_h # => {"Name"=>"foo", "Value"=>3}
table[1].to_h # => {"Name"=>"bar", "Value"=>4}
table[2].to_h # => {"Name"=>"baz", "Value"=>5}
table.by_col! # => #<CSV::Table mode:col row_count:4>

If there are too few values, fills with nil values:

table[1] = [0]
table[1] # => [0, nil, nil]

If there are too many values, ignores the extra values:

table[1] = [0, 1, 2, 3, 4]
table[1] # => [0, 1, 2]

If a single value is given, replaces all fields in the column with that value:

table[1] = 'bat'
table[1] # => ["bat", "bat", "bat"]

Set a Column by Its String Header

If the column exists, it is replaced:

source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
table = CSV.parse(source, headers: true)
new_col = [3, 4, 5]
table.by_col! # => #<CSV::Table mode:col row_count:4>
return_value = table['Value'] = new_col
return_value.equal?(new_col) # => true # Returned the column
table['Value'] # => [3, 4, 5]
# The rows, as revised:
table.by_row! # => #<CSV::Table mode:row row_count:4>
table[0].to_h # => {"Name"=>"foo", "Value"=>3}
table[1].to_h # => {"Name"=>"bar", "Value"=>4}
table[2].to_h # => {"Name"=>"baz", "Value"=>5}
table.by_col! # => #<CSV::Table mode:col row_count:4>

If there are too few values, fills with nil values:

table['Value'] = [0]
table['Value'] # => [0, nil, nil]

If there are too many values, ignores the extra values:

table['Value'] = [0, 1, 2, 3, 4]
table['Value'] # => [0, 1, 2]

If the column does not exist, extends the table by adding columns:

table['Note'] = ['x', 'y', 'z']
table['Note'] # => ["x", "y", "z"]
# The rows, as revised:
table.by_row!
table[0].to_h # => {"Name"=>"foo", "Value"=>0, "Note"=>"x"}
table[1].to_h # => {"Name"=>"bar", "Value"=>1, "Note"=>"y"}
table[2].to_h # => {"Name"=>"baz", "Value"=>2, "Note"=>"z"}
table.by_col!

If a single value is given, replaces all fields in the column with that value:

table['Value'] = 'bat'
table['Value'] # => ["bat", "bat", "bat"]

Stores value v at key in the GW

No documentation available
No documentation available

Set configuration option key to value.

Set key to value in database.

value will be converted to YAML before storage.

See store for more information.

Sets the header field corresponding to the case-insensitive key.

Adds a post-installs hook that will be passed a Gem::DependencyInstaller and a list of installed specifications when Gem::DependencyInstaller#install is complete

Returns the list of Modules nested at the point of call.

module M1
  module M2
    $a = Module.nesting
  end
end
$a           #=> [M1::M2, M1]
$a[0].name   #=> "M1::M2"

Set the handling of the ordering of options and arguments. A RuntimeError is raised if option processing has already started.

The supplied value must be a member of GetoptLong::ORDERINGS. It alters the processing of options as follows:

REQUIRE_ORDER :

Options are required to occur before non-options.

Processing of options ends as soon as a word is encountered that has not been preceded by an appropriate option flag.

For example, if -a and -b are options which do not take arguments, parsing command line arguments of ‘-a one -b two’ would result in ‘one’, ‘-b’, ‘two’ being left in ARGV, and only (‘-a’, ”) being processed as an option/arg pair.

This is the default ordering, if the environment variable POSIXLY_CORRECT is set. (This is for compatibility with GNU getopt_long.)

PERMUTE :

Options can occur anywhere in the command line parsed. This is the default behavior.

Every sequence of words which can be interpreted as an option (with or without argument) is treated as an option; non-option words are skipped.

For example, if -a does not require an argument and -b optionally takes an argument, parsing ‘-a one -b two three’ would result in (‘-a’,”) and (‘-b’, ‘two’) being processed as option/arg pairs, and ‘one’,‘three’ being left in ARGV.

If the ordering is set to PERMUTE but the environment variable POSIXLY_CORRECT is set, REQUIRE_ORDER is used instead. This is for compatibility with GNU getopt_long.

RETURN_IN_ORDER :

All words on the command line are processed as options. Words not preceded by a short or long option flag are passed as arguments with an option of ” (empty string).

For example, if -a requires an argument but -b does not, a command line of ‘-a one -b two three’ would result in option/arg pairs of (‘-a’, ‘one’) (‘-b’, ”), (”, ‘two’), (”, ‘three’) being processed.

Returns the binding associated with prc.

def fred(param)
  proc {}
end

b = fred(99)
eval("param", b.binding)   #=> 99

Return the generated binding object from event.

Note that for c_call and c_return events, the binding returned is the binding of the nearest Ruby method calling the C method, since C methods themselves do not have bindings.

Returns a Binding object, describing the variable and method bindings at the point of call. This object can be used when calling eval to execute the evaluated command in this environment. See also the description of class Binding.

def get_binding(param)
  binding
end
b = get_binding("hello")
eval("param", b)   #=> "hello"

Is this handler a streaming handler?

No documentation available

Returns true if the given instance variable is defined in obj. String arguments are converted to symbols.

class Fred
  def initialize(p1, p2)
    @a, @b = p1, p2
  end
end
fred = Fred.new('cat', 99)
fred.instance_variable_defined?(:@a)    #=> true
fred.instance_variable_defined?("@b")   #=> true
fred.instance_variable_defined?("@c")   #=> false

Returns true if and only if the scan pointer is at the beginning of the line.

s = StringScanner.new("test\ntest\n")
s.bol?           # => true
s.scan(/te/)
s.bol?           # => false
s.scan(/st\n/)
s.bol?           # => true
s.terminate
s.bol?           # => true

Returns an array of instance variable names for the receiver. Note that simply defining an accessor does not create the corresponding instance variable.

class Fred
  attr_accessor :a1
  def initialize
    @iv = 3
  end
end
Fred.new.instance_variables   #=> [:@iv]

Invoked when a reference is made to an undefined constant in mod. It is passed a symbol for the undefined constant, and returns a value to be used for that constant. The following code is an example of the same:

def Foo.const_missing(name)
  name # return the constant name as Symbol
end

Foo::UNDEFINED_CONST    #=> :UNDEFINED_CONST: symbol returned

In the next example when a reference is made to an undefined constant, it attempts to load a file whose name is the lowercase version of the constant (thus class Fred is assumed to be in file fred.rb). If found, it returns the loaded class. It therefore implements an autoload feature similar to Kernel#autoload and Module#autoload.

def Object.const_missing(name)
  @looked_for ||= {}
  str_name = name.to_s
  raise "Class not found: #{name}" if @looked_for[str_name]
  @looked_for[str_name] = 1
  file = str_name.downcase
  require file
  klass = const_get(name)
  return klass if klass
  raise "Class not found: #{name}"
end
Search took: 4ms  ·  Total Results: 2723