るりまサーチ

最速Rubyリファレンスマニュアル検索!
129件ヒット [1-100件を表示] (0.089秒)
トップページ > クエリ:n[x] > クエリ:arguments[x] > ライブラリ:ビルトイン[x]

別のキーワード

  1. etc sc_xopen_enh_i18n
  2. pop n_mails
  3. rsa n=
  4. rsa n
  5. pop3 n_bytes

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

String#concat(*arguments) -> self (6209.0)

self に複数の文字列を破壊的に連結します。

...場合は Integer#chr の結果に相当する文字を末尾に追加します。追加する文字のエンコーディングは self.encoding です。

self を返します。

@param arguments 複数の文字列もしくは 0 以上の整数

//emlist[例][ruby]{
str = "foo"
str.concat
p str...
...# => "foo"

str = "foo"
str.concat "bar", "baz"
p str # => "foobarbaz"

str = "foo"
str.concat("!", 33, 33)
p str # => "foo!!!"
//}...

String#prepend(*arguments) -> String (6209.0)

複数の文字列を先頭に破壊的に追加します。

...複数の文字列を先頭に破壊的に追加します。

@param arguments 追加したい文字列を指定します。

//emlist[例][ruby]{
a = "!!!"
a.prepend # => "!!!"
a # => "!!!"

a = "!!!"
a.prepend "hello ", "world" # => "hello world!!!"
a # => "hello...

Object#then -> Enumerator (6108.0)

self を引数としてブロックを評価し、ブロックの結果を返します。

...]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}

値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。

//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'...
...require 'json'

construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}

ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。

//emlist[][ruby]{
# 条...
...件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}

@see Object#tap...

Object#then {|x| ... } -> object (6108.0)

self を引数としてブロックを評価し、ブロックの結果を返します。

...]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}

値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。

//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'...
...require 'json'

construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}

ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。

//emlist[][ruby]{
# 条...
...件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}

@see Object#tap...

String#concat(other) -> self (6104.0)

self に文字列 other を破壊的に連結します。 other が 整数である場合は other.chr(self.encoding) 相当の文字を末尾に追加します。

...合は other.chr(self.encoding) 相当の文字を末尾に追加します。

self を返します。

@param other 文字列もしくは 0 以上の整数

//emlist[例][ruby]{
str = "string"
str.concat "XXX"
p str # => "stringXXX"

str << "YYY"
p str # => "stringXXXYYY"

str << 65 # 文...
...字AのASCIIコード
p str # => "stringXXXYYYA"
//}...

絞り込み条件を変える

String#prepend(other_str) -> String (6104.0)

文字列 other_str を先頭に破壊的に追加します。

...文字列 other_str を先頭に破壊的に追加します。

@param other_str 追加したい文字列を指定します。

//emlist[例][ruby]{
a = "world"
a.prepend("hello ") # => "hello world"
a # => "hello world"
//}...

ArgumentError (6008.0)

引数の数があっていないときや、数は合っていて、期待される振る舞いを持ってはいるが、期待される値ではないときに発生します。

...、数は合っていて、期待される振る舞いを持ってはいるが、期待される値ではないときに発生します。

例:

Time.at # => wrong number of arguments (0 for 1) (ArgumentError)
Array.new(-1) # => negative array size (ArgumentError)

など

@see TypeError...
...ていて、期待される振る舞いを持ってはいるが、期待される値ではないときに発生します。

例:

Time.at # => wrong number of arguments (given 0, expected 1..2) (ArgumentError)
Array.new(-1) # => negative array size (ArgumentError)

など

@see TypeError...

Data.new(**kwargs) -> Data (3108.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...n 値オブジェクトクラスのインスタンス。

@raise ArgumentError 値オブジェクトのメンバの数より多くの引数を渡した場合に発生します。

//emlist[例][ruby]{
Point = Data.define(:x, :y)

p1 = Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2

p2 = Point.n...
...2.y # => 4
//}

n
ew に渡す引数の数がメンバの数より多い場合は new でエラーになります。

n
ew に渡す引数の数がメンバの数より少ない場合は new ではエラーにならず、そのまま initialize に渡されます。
ユーザが initialize のオ...
...int.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してください。

//emlist[例][ruby]{
Point = Data.define(:x, :y)

Poin...

Data.new(*args) -> Data (3108.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...n 値オブジェクトクラスのインスタンス。

@raise ArgumentError 値オブジェクトのメンバの数より多くの引数を渡した場合に発生します。

//emlist[例][ruby]{
Point = Data.define(:x, :y)

p1 = Point.new(1, 2)
p p1.x # => 1
p p1.y # => 2

p2 = Point.n...
...2.y # => 4
//}

n
ew に渡す引数の数がメンバの数より多い場合は new でエラーになります。

n
ew に渡す引数の数がメンバの数より少ない場合は new ではエラーにならず、そのまま initialize に渡されます。
ユーザが initialize のオ...
...int.new に渡した位置引数の数が多い場合(上から2番目)のみ new でエラーが発生しており、
残りのケースではエラーの発生箇所は new ではなく initialize であることに注意してください。

//emlist[例][ruby]{
Point = Data.define(:x, :y)

Poin...

Object#yield_self -> Enumerator (3108.0)

self を引数としてブロックを評価し、ブロックの結果を返します。

...]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}

値をメソッドチェインのパイプラインに次々と渡すのは良い使い方です。

//emlist[メソッドチェインのパイプライン][ruby]{
require 'open-uri'...
...require 'json'

construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}

ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使えます。

//emlist[][ruby]{
# 条...
...件にあうので何もしない
1.yield_self.detect(&:odd?) # => 1
# 条件に合わないので値を捨てる
2.yield_self.detect(&:odd?) # => nil
//}

@see Object#tap...

絞り込み条件を変える

Struct.new(*args, keyword_init: nil) -> Class (3108.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定できる...
...名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。String または Symbol を指定します。
@param keyword_init true を指定すると、キーワード引数で初期化する構造体を定義します。
Rub...
...ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unknown keywords...
...めの可変長引数。String または Symbol を指定します。
@param keyword_init 構造体クラスのインスタンスを生成する際に、キーワード引数を使用するかどうかを指定します。値の意味は次のとおりです。

* nil: キーワード引数と位...
...][ruby]{
Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1) # => #<struct Point1 x=1, y=nil>
Point1.new(y: 2) # => #<struct Point1 x=nil, y=2>
Point1.new(x: 1, y:...

Struct.new(*args, keyword_init: nil) {|subclass| block } -> Class (3108.0)

Struct クラスに新しいサブクラスを作って、それを返します。

...][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}

実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定できる...
...名は Symbol で指定するのが無難です。

@param args 構造体を定義するための可変長引数。String または Symbol を指定します。
@param keyword_init true を指定すると、キーワード引数で初期化する構造体を定義します。
Rub...
...ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # ArgumentError (unknown keywords...
...めの可変長引数。String または Symbol を指定します。
@param keyword_init 構造体クラスのインスタンスを生成する際に、キーワード引数を使用するかどうかを指定します。値の意味は次のとおりです。

* nil: キーワード引数と位...
...][ruby]{
Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1) # => #<struct Point1 x=1, y=nil>
Point1.new(y: 2) # => #<struct Point1 x=nil, y=2>
Point1.new(x: 1, y:...

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

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

...なければ nil です。

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

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

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

Kernel.#lambda -> Proc (3008.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...ます。Proc.new に近い働きをします。

ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトとして返します。呼び出し元のメソッドがブロックなし
で呼ばれると ArgumentError 例外...
...warning: tried to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。

ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capt...
...uring the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。

@raise ArgumentError スタック上にブロックがないのにブロックを省略した呼び出し...

Kernel.#lambda { ... } -> Proc (3008.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...ます。Proc.new に近い働きをします。

ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトとして返します。呼び出し元のメソッドがブロックなし
で呼ばれると ArgumentError 例外...
...warning: tried to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。

ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capt...
...uring the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。

@raise ArgumentError スタック上にブロックがないのにブロックを省略した呼び出し...
...Proc.new に近い働きをします。


また、lambda に & 引数を渡すのは推奨されません。& 引数ではなくてブロック記法で記述する必要があります。

& 引数を渡した lambda は Warning[:deprecated] = true のときに警告メッセージ
「warning: lam...
...c without lambda instead」
を出力します。

@raise ArgumentError ブロックを省略した呼び出しを行ったときに発生します。

//emlist[例][ruby]{
def foo &block
lambda(&block)
end

it = foo{p 12}
it.call #=> 12
//}

@see Proc,Proc.new

===[a:should_use_next] 手続きを...
...では Proc#call)
へジャンプし値を返すには next を使います。break や return ではありません。


//emlist[例][ruby]{
def foo
f = Proc.new{
n
ext 1
2 # この行に到達することはない
}
end

p foo().call #=> 1
//}

===[a:block] Proc オ...
...oc without lambda instead」
を出力します。

@raise ArgumentError ブロックを省略した呼び出しを行ったときに発生します。

//emlist[例][ruby]{
def foo &block
proc(&block)
end

it = foo{p 12}
it.call #=> 12
//}

@see Proc,Proc.new

===[a:should_use_next] 手続きを...

絞り込み条件を変える

Kernel.#proc -> Proc (3008.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...ます。Proc.new に近い働きをします。

ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトとして返します。呼び出し元のメソッドがブロックなし
で呼ばれると ArgumentError 例外...
...warning: tried to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。

ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capt...
...uring the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。

@raise ArgumentError スタック上にブロックがないのにブロックを省略した呼び出し...

Kernel.#proc { ... } -> Proc (3008.0)

与えられたブロックから手続きオブジェクト (Proc のインスタンス) を生成して返します。Proc.new に近い働きをします。

...ます。Proc.new に近い働きをします。

ブロックが指定されなければ、呼び出し元のメソッドで指定されたブロック
を手続きオブジェクトとして返します。呼び出し元のメソッドがブロックなし
で呼ばれると ArgumentError 例外...
...warning: tried to create Proc object without a block」
が出力され、Ruby 2.7 では
ArgumentError (tried to create Proc object without a block)
が発生します。

ブロックを指定しない proc は、Ruby 2.7 では
$VERBOSE = true のときには警告メッセージ
「warning: Capt...
...uring the given block using Proc.new is deprecated; use `&block` instead」
が出力され、Ruby 3.0 では
ArgumentError (tried to create Proc object without a block)
が発生します。

@raise ArgumentError スタック上にブロックがないのにブロックを省略した呼び出し...
<< 1 2 > >>