module IN
contains ARPA Internet specific RRs.
Assigns elements in self
; returns the given object
.
When Integer
argument index
is given, assigns object
to an element in self
.
If index
is non-negative, assigns object
the element at offset index
:
a = [:foo, 'bar', 2] a[0] = 'foo' # => "foo" a # => ["foo", "bar", 2]
If index
is greater than self.length
, extends the array:
a = [:foo, 'bar', 2] a[7] = 'foo' # => "foo" a # => [:foo, "bar", 2, nil, nil, nil, nil, "foo"]
If index
is negative, counts backwards from the end of the array:
a = [:foo, 'bar', 2] a[-1] = 'two' # => "two" a # => [:foo, "bar", "two"]
When Integer
arguments start
and length
are given and object
is not an Array, removes length - 1
elements beginning at offset start
, and assigns object
at offset start
:
a = [:foo, 'bar', 2] a[0, 2] = 'foo' # => "foo" a # => ["foo", 2]
If start
is negative, counts backwards from the end of the array:
a = [:foo, 'bar', 2] a[-2, 2] = 'foo' # => "foo" a # => [:foo, "foo"]
If start
is non-negative and outside the array ( >= self.size
), extends the array with nil
, assigns object
at offset start
, and ignores length
:
a = [:foo, 'bar', 2] a[6, 50] = 'foo' # => "foo" a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
If length
is zero, shifts elements at and following offset start
and assigns object
at offset start
:
a = [:foo, 'bar', 2] a[1, 0] = 'foo' # => "foo" a # => [:foo, "foo", "bar", 2]
If length
is too large for the existing array, does not extend the array:
a = [:foo, 'bar', 2] a[1, 5] = 'foo' # => "foo" a # => [:foo, "foo"]
When Range
argument range
is given and object
is an Array, removes length - 1
elements beginning at offset start
, and assigns object
at offset start
:
a = [:foo, 'bar', 2] a[0..1] = 'foo' # => "foo" a # => ["foo", 2]
if range.begin
is negative, counts backwards from the end of the array:
a = [:foo, 'bar', 2] a[-2..2] = 'foo' # => "foo" a # => [:foo, "foo"]
If the array length is less than range.begin
, assigns object
at offset range.begin
, and ignores length
:
a = [:foo, 'bar', 2] a[6..50] = 'foo' # => "foo" a # => [:foo, "bar", 2, nil, nil, nil, "foo"]
If range.end
is zero, shifts elements at and following offset start
and assigns object
at offset start
:
a = [:foo, 'bar', 2] a[1..0] = 'foo' # => "foo" a # => [:foo, "foo", "bar", 2]
If range.end
is negative, assigns object
at offset start
, retains range.end.abs -1
elements past that, and removes those beyond:
a = [:foo, 'bar', 2] a[1..-1] = 'foo' # => "foo" a # => [:foo, "foo"] a = [:foo, 'bar', 2] a[1..-2] = 'foo' # => "foo" a # => [:foo, "foo", 2] a = [:foo, 'bar', 2] a[1..-3] = 'foo' # => "foo" a # => [:foo, "foo", "bar", 2] a = [:foo, 'bar', 2]
If range.end
is too large for the existing array, replaces array elements, but does not extend the array with nil
values:
a = [:foo, 'bar', 2] a[1..5] = 'foo' # => "foo" a # => [:foo, "foo"]
Assign value
to the fiber storage variable identified by key
. The variable is created if it doesn’t exist.
key
must be a Symbol
, otherwise a TypeError
is raised.
See also Fiber::[]
.
Sets the value of an attribute.
require "ostruct" person = OpenStruct.new("name" => "John Smith", "age" => 70) person[:age] = 42 # equivalent to person.age = 42 person.age # => 42
Assigns a value to a member.
With symbol or string argument name
given, assigns the given value
to the named member; returns value
:
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe[:zip] = 54321 # => 54321 joe # => #<struct Customer name="Joe Smith", address="123 Maple, Anytown NC", zip=54321>
Raises NameError
if name
is not the name of a member.
With integer argument n
given, assigns the given value
to the n
-th member if n
is in range; see Array Indexes at Array
:
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe[2] = 54321 # => 54321 joe[-3] = 'Joseph Smith' # => "Joseph Smith" joe # => #<struct Customer name="Joseph Smith", address="123 Maple, Anytown NC", zip=54321>
Raises IndexError
if n
is out of range.
Sets the value to WIN32OLE
object specified by a1, a2, …
dict = WIN32OLE.new('Scripting.Dictionary') dict.add('ruby', 'RUBY') dict['ruby'] = 'Ruby' puts dict['ruby'] # => 'Ruby'
Remark: You can not use this method to set the property value.
excel = WIN32OLE.new('Excel.Application') # excel['Visible'] = true # This is error !!! excel.Visible = true # You should to use this style to set the property.
Associates the given value
with the given key
; returns value
.
If the given key
exists, replaces its value with the given value
; the ordering is not affected (see Entry Order):
h = {foo: 0, bar: 1} h[:foo] = 2 # => 2 h.store(:bar, 3) # => 3 h # => {:foo=>2, :bar=>3}
If key
does not exist, adds the key
and value
; the new entry is last in the order (see Entry Order):
h = {foo: 0, bar: 1} h[:baz] = 2 # => 2 h.store(:bat, 3) # => 3 h # => {:foo=>0, :bar=>1, :baz=>2, :bat=>3}
Creates, updates, or deletes the named environment variable, returning the value. Both name
and value
may be instances of String
. See Valid Names and Values.
If the named environment variable does not exist:
If value
is nil
, does nothing.
ENV.clear ENV['foo'] = nil # => nil ENV.include?('foo') # => false ENV.store('bar', nil) # => nil ENV.include?('bar') # => false
If value
is not nil
, creates the environment variable with name
and value
:
# Create 'foo' using ENV.[]=. ENV['foo'] = '0' # => '0' ENV['foo'] # => '0' # Create 'bar' using ENV.store. ENV.store('bar', '1') # => '1' ENV['bar'] # => '1'
If the named environment variable exists:
If value
is not nil
, updates the environment variable with value value
:
# Update 'foo' using ENV.[]=. ENV['foo'] = '2' # => '2' ENV['foo'] # => '2' # Update 'bar' using ENV.store. ENV.store('bar', '3') # => '3' ENV['bar'] # => '3'
If value
is nil
, deletes the environment variable:
# Delete 'foo' using ENV.[]=. ENV['foo'] = nil # => nil ENV.include?('foo') # => false # Delete 'bar' using ENV.store. ENV.store('bar', nil) # => nil ENV.include?('bar') # => false
Raises an exception if name
or value
is invalid. See Invalid Names and Values.
Creates or replaces the value for the given key
:
example_store do |store| temp.transaction do temp[:bat] = 3 end end
See also Hierarchical Values.
Raises an exception if called outside a transaction block.
set a value in ractor-local storage
Attribute Assignment—Sets or creates the value of a fiber-local variable, using either a symbol or a string.
See also Thread#[]
.
For thread-local variables, please see thread_variable_set
and thread_variable_get
.
Sets the warning flags for category
. See Warning.[]
for the categories.
Assigns the underlying string as other_string
, and sets position to zero; returns other_string
:
StringIO.open('foo') do |strio| p strio.string strio.string = 'bar' p strio.string end
Output:
"foo" "bar"
Related: StringIO#string
(returns the underlying string).
Changes the string being scanned to str
and resets the scanner. Returns str
.
Set
struct member name
, to value val
. If more arguments are specified, writes the string of bytes to the memory at the given offset
and length
.
Examples:
my_struct = struct(['int id']).malloc my_struct['id'] = 1 my_struct[0, 4] = "\x01\x00\x00\x00".b my_struct.id # => 1
Set
the value at index
to int
.
Or, set the memory at start
until length
with the contents of string
, the memory from dl_cptr
, or the memory pointed at by the memory address addr
.
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
Set
the element of WIN32OLE_VARIANT object(OLE array) to val. This method is available only when the variant type of WIN32OLE_VARIANT object is VT_ARRAY.
REMARK:
The all indices should be 0 or natural number and lower than or equal to max indices. (This point is different with Ruby Array indices.) obj = WIN32OLE_VARIANT.new([[1,2,3],[4,5,6]]) obj[0,0] = 7 obj[1,0] = 8 p obj.value # => [[7,2,3], [8,5,6]] obj[2,0] = 9 # => WIN32OLERuntimeError obj[0, -1] = 9 # => WIN32OLERuntimeError
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>