るりまサーチ

最速Rubyリファレンスマニュアル検索!
326件ヒット [201-300件を表示] (0.218秒)

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

オブジェクト

キーワード

検索結果

<< < 1 2 3 4 > >>

Hash#transform_keys! -> Enumerator (8014.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...# => {"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}
//}

@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_values!...
...# => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_values!...

Hash#transform_keys! {|key| ... } -> self (8014.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...# => {"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}
//}

@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_values!...
...# => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_values!...

Hash#transform_keys!(hash) -> self (8014.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...# => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_values!...

Hash#transform_keys(hash) -> Hash (8014.0)

すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。

...") # => {"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}
//}

@see Hash#transform_keys!
@see Hash#transform_values
@see Hash#transform_values!...

Regexp#match(str, pos = 0) -> MatchData | nil (8014.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...az").to_a.values_at(1,2,3) # => ["foo", "bar", "baz"]
//}

=== 便利な使いかた
正規表現にマッチした部分文字列だけが必要な場合に、

//emlist[][ruby]{
bar = /foo(.*)baz/.match("foobarbaz").to_a[1]

foo, bar, baz = /(foo)(bar)(baz)/.match("foobarbaz").to_a.values_at(1,2,3...

絞り込み条件を変える

Regexp#match(str, pos = 0) {|m| ... } -> object | nil (8014.0)

指定された文字列 str に対して位置 pos から自身が表す正規表現によるマッ チングを行います。マッチした場合には結果を MatchData オブジェクトで返し ます。 マッチしなかった場合 nil を返します。

...az").to_a.values_at(1,2,3) # => ["foo", "bar", "baz"]
//}

=== 便利な使いかた
正規表現にマッチした部分文字列だけが必要な場合に、

//emlist[][ruby]{
bar = /foo(.*)baz/.match("foobarbaz").to_a[1]

foo, bar, baz = /(foo)(bar)(baz)/.match("foobarbaz").to_a.values_at(1,2,3...

Hash#[](key) -> object | nil (8008.0)

key に関連づけられた値を返します。

..."all"}
p h[:ab] #=> "some"
p h[:ef] #=> nil

h1 = Hash.new("default value")
p h1[:non] #=> "default value"

h2 = Hash.new {|*arg| arg}
p h2[:non] #=> [{}, :non]
//}

@see Hash.new, Hash#fetch,Hash#values_at,Hash#key?, Hash#default, Hash#default_proc...

Hash#keys -> [object] (8008.0)

全キーの配列を返します。

...全キーの配列を返します。

//emlist[例][ruby]{
h1 = { "a" => 100, 2 => ["some"], :c => "c" }
p h1.keys #=> ["a", 2, :c]
//}

@see Hash#values,Hash#to_a...

Hash#to_a -> [Array] (8008.0)

キーと値からなる 2 要素の配列を並べた配列を生成して返します。

...キーと値からなる 2 要素の配列を並べた配列を生成して返します。

//emlist[例][ruby]{
h1 = { "a" => 100, 2 => ["some"], :c => "c" }
p h1.to_a #=> c, "c"
//}

@see Hash#keys,Hash#values...

Struct.[](*args) -> Struct (8008.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

絞り込み条件を変える

Struct.new(*args) -> Struct (8008.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...なければ nil です。

@return 構造体クラスのインスタンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Struct#to_a -> [object] (8003.0)

構造体のメンバの値を配列にいれて返します。

構造体のメンバの値を配列にいれて返します。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_a
# => ["Joe Smith", "123 Maple, Anytown NC", 12345]
//}

[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してくだ...
<< < 1 2 3 4 > >>