Puts data onto the table.
Set
a Row by Its Integer Index
Form: table[n] = row
, n
an Integer, row
a CSV::Row instance or an Array of fields.
Access mode: :row
or :col_or_row
.
Return value: row
.
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
Form: table[n] = array_of_fields
, n
an Integer, array_of_fields
an Array of String fields.
Access mode: :col
.
Return value: array_of_fields
.
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
Form: table[header] = field_or_array_of_fields
, header
a String header, field_or_array_of_fields
a field value or an Array of String fields.
Access mode: :col
or :col_or_row
.
Return value: field_or_array_of_fields
.
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
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.
Associates the given value
with the given key
.
If the given key
exists, replaces its value with the given value
; the ordering is not affected.
Associates the given value
with the given key
The reference to key
is weak, so when there is no other reference to key
it may be garbage collected.
If the given key
exists, replaces its value with the given value
; the ordering is not affected
Sets the value for the case-insensitive key
to val
, overwriting the previous value if the field exists; see Fields:
req = Net::HTTP::Get.new(uri) req['Accept'] # => "*/*" req['Accept'] = 'text/html' req['Accept'] # => "text/html"
Note that some field values may be set via convenience methods; see Setters.
Create a new InterpolatedStringNode
node
Create a new InterpolatedXStringNode
node
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"
Sets the ordering; see Ordering; returns the new ordering.
If the given ordering
is PERMUTE
and environment variable POSIXLY_CORRECT
is defined, sets the ordering to REQUIRE_ORDER
; otherwise sets the ordering to ordering
:
options = GetoptLong.new options.ordering == GetoptLong::PERMUTE # => true options.ordering = GetoptLong::RETURN_IN_ORDER options.ordering == GetoptLong::RETURN_IN_ORDER # => true ENV['POSIXLY_CORRECT'] = 'true' options.ordering = GetoptLong::PERMUTE options.ordering == GetoptLong::REQUIRE_ORDER # => true
Raises an exception if ordering
is invalid.
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 method will return nil
, 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 Binding#eval
to execute the evaluated command in this environment, or extracting its local variables.
class User def initialize(name, position) @name = name @position = position end def get_binding binding end end user = User.new('Joan', 'manager') template = '{name: @name, position: @position}' # evaluate template in context of the object eval(template, user.get_binding) #=> {:name=>"Joan", :position=>"manager"}
Binding#local_variable_get
can be used to access the variables whose names are reserved Ruby keywords:
# This is valid parameter declaration, but `if` parameter can't # be accessed by name, because it is a reserved word. def validate(field, validation, if: nil) condition = binding.local_variable_get('if') return unless condition # ...Some implementation ... end validate(:name, :empty?, if: false) # skips validation validate(:name, :empty?, if: true) # performs validation
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 help string.
tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', 'IWebBrowser') puts tobj.helpstring # => Web Browser interface
Create a new StringNode
node
Create a new XStringNode
node
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
Is this handler a streaming handler?
Create a new InstanceVariableAndWriteNode
node