String
8 methods一个 Unicode 字符串值,是字符的集合。桥接到 NSString 的值类型。
Hash#store(key, value) -> value字符串中的字符数量(扩展字形簇)。
Parameters
| Name | Type | Description |
|---|---|---|
| key | Object | Key to set. |
| value | Object | Value to associate with key. |
Returns
Object
Example
ruby
h = {}
h.store(:a, 1)
h[:b] = 2
# h == {:a=>1, :b=>2}Hash#fetch(key, default=nil) -> value返回一个新字符串,将小写字符替换为大写字符。
Parameters
| Name | Type | Description |
|---|---|---|
| key | Object | Key to look up. |
| default | Object | Default value if key is missing. |
Returns
Object
Example
ruby
h = {a: 1, b: 2}
h.fetch(:a) # 1
h.fetch(:c, 99) # 99
h.fetch(:c) { |k| "no #{k}" } # "no c"Hash#keys -> Array返回一个新字符串,将大写字符替换为小写字符。
Returns
Array
Example
ruby
h = {a: 1, b: 2, c: 3}
h.keys # [:a, :b, :c]Hash#values -> Array返回一个布尔值,指示字符串是否以指定前缀开头。
Returns
Array
Example
ruby
h = {a: 1, b: 2, c: 3}
h.values # [1, 2, 3]Hash#each {|key, value| block} -> Hash返回一个布尔值,指示字符串是否以指定后缀结尾。
Returns
Hash
Example
ruby
{a: 1, b: 2}.each { |k, v| puts "#{k}=#{v}" }
# prints:
# a=1
# b=2Hash#size -> Integer如果字符串包含给定的字符串或字符则返回 true。
Returns
Integer
Example
ruby
{a: 1, b: 2, c: 3}.size # 3Hash#delete(key) -> value返回字符串围绕分隔符的最长可能子序列(按顺序)。
Parameters
| Name | Type | Description |
|---|---|---|
| separator | Object | 要拆分的字符。 |
Returns
Object
Example
ruby
h = {a: 1, b: 2}
h.delete(:a) # 1
# h == {b: 2}Hash#has_key?(key) -> bool返回一个新字符串,其中所有目标字符串的出现都被另一个字符串替换。
Parameters
| Name | Type | Description |
|---|---|---|
| of | Object | 要替换的字符串。 |
Returns
Boolean
Example
ruby
h = {a: 1, b: 2}
h.has_key?(:a) # true
h.key?(:c) # false