るりまサーチ

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

別のキーワード

  1. objectspace each_object
  2. _builtin each_object
  3. object send
  4. object to_enum
  5. object enum_for

ライブラリ

キーワード

検索結果

Kernel.#String(arg) -> String (18238.0)

引数を文字列(String)に変換した結果を返します。

...引数を文字列(String)に変換した結果を返します。

arg.to_s を呼び出して文字列に変換します。
arg が文字列の場合、何もせず arg を返します。

@param arg 変換対象のオブジェクトです。
@raise TypeError to_s の返り値が文字列でなけ...
...れば発生します。

//emlist[例][ruby]{
class Foo
def to_s
"hogehoge"
end
end

arg = Foo.new
p String(arg) #=> "hogehoge"
//}

@see Object#to_s,String...

Kernel.#format(format, *arg) -> String (116.0)

format 文字列を C 言語の sprintf と同じように解釈し、 引数をフォーマットした文字列を返します。

...トした文字列を返します。

@param format フォーマット文字列です。
@param arg フォーマットされる引数です。
@see Kernel.#printf,Time#strftime,Date.strptime

=== sprintf フォーマット

Ruby の sprintf フォーマットは基本的に C 言語の sprintf(3)...
...けが意味を持ちます。

: s

文字列を出力します。

引数が String オブジェクトでなければ to_s メソッドにより文字列化
したものを引数として扱います。

: p

Object
#inspect の結果を出力します。
//emlist[][ruby]{
p sprintf("%s", /e+/)...
...tf("%p", /e+/) #=> "/e+/"
//}


: d
: i

引数の数値を10進表現の整数として出力します。

引数が整数でなければ関数 Kernel.#Integer と同じ規則で整数に
変換されます。

//emlist[][ruby]{
p sprintf("%d", -1) #=> "-1"
p sprintf("%d", 3.1) #=> "3"
p sprint...

Kernel.#sprintf(format, *arg) -> String (116.0)

format 文字列を C 言語の sprintf と同じように解釈し、 引数をフォーマットした文字列を返します。

...トした文字列を返します。

@param format フォーマット文字列です。
@param arg フォーマットされる引数です。
@see Kernel.#printf,Time#strftime,Date.strptime

=== sprintf フォーマット

Ruby の sprintf フォーマットは基本的に C 言語の sprintf(3)...
...けが意味を持ちます。

: s

文字列を出力します。

引数が String オブジェクトでなければ to_s メソッドにより文字列化
したものを引数として扱います。

: p

Object
#inspect の結果を出力します。
//emlist[][ruby]{
p sprintf("%s", /e+/)...
...tf("%p", /e+/) #=> "/e+/"
//}


: d
: i

引数の数値を10進表現の整数として出力します。

引数が整数でなければ関数 Kernel.#Integer と同じ規則で整数に
変換されます。

//emlist[][ruby]{
p sprintf("%d", -1) #=> "-1"
p sprintf("%d", 3.1) #=> "3"
p sprint...

Kernel.#gets(rs = $/) -> String | nil (115.0)

ARGFから一行読み込んで、それを返します。 行の区切りは引数 rs で指定した文字列になります。

...< 'c.txt'
p gets #=> "hello\n"
p gets(nil) #=> "it\ncommon\n"
p gets("") #=> "ARGF\n\n"
p gets('、') #=> "# スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と\n# みなして、"
p gets #=> "それらのファイルを連結した 1 つの仮想ファイルを表す...
...mmon
//}

//emlist[c.txt][ruby]{
ARGF

# スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と
# みなして、それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。
//}


@see $/,ARGF,Kernel.#readlines,Kernel.#readline...

Kernel.#readline(rs = $/) -> String (115.0)

ARGFから一行読み込んで、それを返します。 行の区切りは引数 rs で指定した文字列になります。

...adline #=> "hello\n"
p readline(nil) #=> "it\ncommon\n"
p readline("") #=> "ARGF\n\n"
p readline('、') #=> "スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と\nみなして、"
p readline #=> "それらのファイルを連結した 1 つの仮想ファイルを表...
...t ---
hello
it
common
# --- c.txt ---
ARGF
# スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と
# みなして、それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。
//}


@see $/,ARGF,Kernel.#readlines,Kernel.#gets...

絞り込み条件を変える

Kernel.#open(name, mode = &#39;r&#39;, perm = nil, options = {}) -> StringIO | Tempfile | IO (103.0)

name が http:// や ftp:// で始まっている文字列なら URI のリソースを 取得した上で StringIO オブジェクトまたは Tempfile オブジェクトとして返します。 返されるオブジェクトは OpenURI::Meta モジュールで extend されています。

...name が http:// や ftp:// で始まっている文字列なら URI のリソースを
取得した上で StringIO オブジェクトまたは Tempfile オブジェクトとして返します。
返されるオブジェクトは OpenURI::Meta モジュールで extend されています。

name...
...イル名として扱われ、従来の
Kernel
.#open(name, *rest) が呼ばれます。

ブロックを与えた場合は上の場合と同様、name が http:// や ftp:// で
始まっている文字列なら URI のリソースを取得した上で StringIO オブジェクト
または Tempfile...
...ram mode モードを文字列で与えます。Kernel.#open と同じです。

@param perm open(2) の第 3 引数のように、ファイルを生成する場合のファイルのパーミッションを
整数で指定します。Kernel.#open と同じです

@param options ハッシ...
...uby2.7以降、open-uriにより拡張されたKernel.openでURLを開くときにwarningが表示されるようになりました。

require 'open-uri'
open("http://www.ruby-lang.org/") {|f|
# ...
}
#=> warning: calling URI.open via Kernel#open is deprecated, call URI.open directly or...

Kernel.#Integer(arg, base = 0) -> Integer (32.0)

引数を整数 (Fixnum,Bignum) に変換した結果を返します。

...teger(4_000) #=> 4000
p Integer(9.88) #=> 9

p Integer(nil) # can't convert nil into Integer (TypeError)
p Integer(Object.new) # cannot convert Object into Integer (TypeError)

p Integer("10") #=> 10
p Integer("10", 2) #=> 2
p Integer("0d10") #=> 10
p Integer("010")...
...teger("1\n0") # `Integer': invalid value for Integer: "1\n0" (ArgumentError)
p Integer("hoge") # `Integer': invalid value for Integer: "hoge" (ArgumentError)
p Integer("") # `Integer': invalid value for Integer: "" (ArgumentError)
//}

@see String#hex,String#oct,String#to_i,Integer...

Kernel.#Integer(arg, base = 0, exception: true) -> Integer | nil (32.0)

引数を整数 に変換した結果を返します。

...teger(4_000) #=> 4000
p Integer(9.88) #=> 9

p Integer(nil) # can't convert nil into Integer (TypeError)
p Integer(Object.new) # cannot convert Object into Integer (TypeError)

p Integer("10") #=> 10
p Integer("10", 2) #=> 2
p Integer("0d10") #=> 10
p Integer("010")...
...teger("1\n0") # `Integer': invalid value for Integer: "1\n0" (ArgumentError)
p Integer("hoge") # `Integer': invalid value for Integer: "hoge" (ArgumentError)
p Integer("") # `Integer': invalid value for Integer: "" (ArgumentError)
//}

@see String#hex,String#oct,String#to_i,Integer...

Kernel.#Float(arg) -> Float (26.0)

引数を浮動小数点数(Float)に変換した結果を返します。

...換し、文字列の場合
は整数や浮動小数点数と見なせるもののみ変換します。

メソッド Float は文字列に対し String#to_f よりも厳密な変換を行います。

@param arg 変換対象のオブジェクトです。
@raise ArgumentError 整数や浮動小数...
...#=> 4.0
p Float(4_000) #=> 4000.0
p Float(9.88) #=> 9.88

p Float(Time.gm(1986)) #=> 504921600.0
p Float(Object.new) # can't convert Object into Float (TypeError)
p Float(nil) # can't convert nil into Float (TypeError)

p Float("10") #=> 10.0
p Float("10...
...alid value for Float(): "0xa.a" (ArgumentError)
p Float(" \n10\s \t") #=> 10.0 # 先頭と末尾の空白類は無視される
p Float("1\n0") # invalid value for Float(): "1\n0" (ArgumentError)
p Float("") # invalid value for Float(): "" (ArgumentError)
//}

@see String#to_f,Float...

Kernel.#Float(arg, exception: true) -> Float | nil (26.0)

引数を浮動小数点数(Float)に変換した結果を返します。

...換し、文字列の場合
は整数や浮動小数点数と見なせるもののみ変換します。

メソッド Float は文字列に対し String#to_f よりも厳密な変換を行います。

@param arg 変換対象のオブジェクトです。
@param exception false を指定すると、...
...#=> 4.0
p Float(4_000) #=> 4000.0
p Float(9.88) #=> 9.88

p Float(Time.gm(1986)) #=> 504921600.0
p Float(Object.new) # can't convert Object into Float (TypeError)
p Float(nil) # can't convert nil into Float (TypeError)

p Float("10") #=> 10.0
p Float("10...
...alid value for Float(): "0xa.a" (ArgumentError)
p Float(" \n10\s \t") #=> 10.0 # 先頭と末尾の空白類は無視される
p Float("1\n0") # invalid value for Float(): "1\n0" (ArgumentError)
p Float("") # invalid value for Float(): "" (ArgumentError)
//}

@see String#to_f,Float...

絞り込み条件を変える