ライブラリ
- ビルトイン (323)
- continuation (12)
- open-uri (16)
- pp (4)
- uri (12)
キーワード
- Array (12)
- Float (12)
- Integer (12)
- Rational (12)
- String (12)
- URI (12)
- binding (12)
- callcc (12)
- catch (24)
- eval (24)
- format (12)
- gets (12)
-
global
_ variables (12) - lambda (13)
-
local
_ variables (12) - loop (24)
- open (40)
- p (12)
- pp (12)
- proc (14)
- putc (12)
- readline (12)
-
require
_ relative (12) - sprintf (12)
- throw (12)
検索結果
先頭5件
-
Kernel
. # Array(arg) -> Array (114.0) -
引数を配列(Array)に変換した結果を返します。
...します。
@param arg 変換対象のオブジェクトです。
@raise TypeError to_ary, to_a の返り値が配列でなければ発生します
//emlist[例][ruby]{
p Array({:it => 3}) #=> [[:it, 3]]
p Array(nil) #=> []
p Array("fefe") #=> ["fefe"]
//}
@see Object#to_a,Object#to_ary,Array... -
Kernel
. # Float(arg) -> Float (114.0) -
引数を浮動小数点数(Float)に変換した結果を返します。
...> 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("10e2") #=>......1000.0
p Float("1e-2") #=> 0.01
p Float(".1") #=> 0.1
p Float("0xa") #=> 10.0
p Float("nan") # invalid value for Float(): "nan" (ArgumentError)
p Float("INF") # invalid value for Float(): "INF" (ArgumentError)
p Float("-Inf") # invalid value for Float(): "-......Inf" (ArgumentError)
p Float(("10" * 1000)) #=> Infinity
p Float("0xa.a") # invalid 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("")... -
Kernel
. # Float(arg , exception: true) -> Float | nil (114.0) -
引数を浮動小数点数(Float)に変換した結果を返します。
...> 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("10e2") #=>......1000.0
p Float("1e-2") #=> 0.01
p Float(".1") #=> 0.1
p Float("0xa") #=> 10.0
p Float("nan") # invalid value for Float(): "nan" (ArgumentError)
p Float("INF") # invalid value for Float(): "INF" (ArgumentError)
p Float("-Inf") # invalid value for Float(): "-......Inf" (ArgumentError)
p Float(("10" * 1000)) #=> Infinity
p Float("0xa.a") # invalid 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("")... -
Kernel
. # Integer(arg , base = 0) -> Integer (114.0) -
引数を整数 (Fixnum,Bignum) に変換した結果を返します。
...#=> 4
p Integer(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 I......nteger("010") #=> 8
p Integer("0o10") #=> 8
p Integer("0x10") #=> 16
p Integer("0b10") #=> 2
p Integer(" \n10\t ") #=> 10 # 先頭と末尾の空白類は無視される
p Integer("1\n0") # `Integer': invalid value for Integer: "1\n0" (ArgumentError)
p Integer("hoge") # `Int... -
Kernel
. # Integer(arg , base = 0 , exception: true) -> Integer | nil (114.0) -
引数を整数 (Fixnum,Bignum) に変換した結果を返します。
...#=> 4
p Integer(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 I......nteger("010") #=> 8
p Integer("0o10") #=> 8
p Integer("0x10") #=> 16
p Integer("0b10") #=> 2
p Integer(" \n10\t ") #=> 10 # 先頭と末尾の空白類は無視される
p Integer("1\n0") # `Integer': invalid value for Integer: "1\n0" (ArgumentError)
p Integer("hoge") # `Int... -
Kernel
. # gets(rs = $ / ) -> String | nil (114.0) -
ARGFから一行読み込んで、それを返します。 行の区切りは引数 rs で指定した文字列になります。
....rb][ruby]{
ARGV << 'b.txt' << '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 つ......ファイルを表すオブジェクトです。\n"
p gets #=> nil
p readline # end of file reached (EOFError)
//}
//emlist[b.txt][ruby]{
hello
it
common
//}
//emlist[c.txt][ruby]{
ARGF
# スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と
# みなして、それ......らのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。
//}
@see $/,ARGF,Kernel.#readlines,Kernel.#readline... -
Kernel
. # readline(rs = $ / ) -> String (114.0) -
ARGFから一行読み込んで、それを返します。 行の区切りは引数 rs で指定した文字列になります。
...-
ARGV << 'b.txt' << 'c.txt'
p readline #=> "hello\n"
p readline(nil) #=> "it\ncommon\n"
p readline("") #=> "ARGF\n\n"
p readline('、') #=> "スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と\nみなして、"
p readline #=> "それらのファイルを連結した......t ---
hello
it
common
# --- c.txt ---
ARGF
# スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と
# みなして、それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。
//}
@see $/,ARGF,Kernel.#readlines,Kernel.#gets... -
Kernel
. # require _ relative(relative _ feature) -> bool (114.0) -
現在のファイルからの相対パスで require します。
...じです。
Kernel.#eval などで文字列を評価した場合に、そこから
require_relative を呼出すと必ず失敗します。
@param relative_feature ファイル名の文字列です。
@raise LoadError ロードに失敗した場合に発生します。
@see Kernel.#require
=== r......の扱い方はKernel.#loadでも同様です。
//emlist[例][ruby]{
# ---------- some.rb -----------
$a = 1
@a = 1
A = 1
a = 1
# ---------- end some.rb -------
require 'some'
p $a #=> 1
p @a #=> 1
p A #=> 1
p a # undefined local variable or method `a' for #<Object:0x294f9ec @a=1> (NameError)
//}... -
Kernel
. # throw(tag , value = nil) -> () (114.0) -
Kernel.#catchとの組み合わせで大域脱出を行います。 throw は同じ tag を指定した catch のブロックの終わりまでジャンプします。
...
Kernel.#catchとの組み合わせで大域脱出を行います。 throw
は同じ tag を指定した catch のブロックの終わりまでジャンプします。
throw は探索時に呼び出しスタックをさかのぼるので、
ジャンプ先は同じメソッド内にあるとは限......。
同じ tag で待っている catch が存在しない場合は、例外で
スレッドが終了します。
同じ tag であるとは Object#object_id が同じであるという意味です。
@param tag catch の引数に対応する任意のオブジェクトです。
@param value catch......いる catch が存在しない場合に発生します。
//emlist[例][ruby]{
def foo
throw :exit, 25
end
ret = catch(:exit) do
begin
foo
some_process() # 絶対に実行されない
10
ensure
puts "ensure"
end
end
puts ret
#=> ensure
# 25
//}
@see Kernel.#catch... -
Kernel
. # Rational(x , y = 1) -> Rational (108.0) -
引数を有理数(Rational)に変換した結果を返します。
...onal オブジェクトを
返します。
//emlist[例][ruby]{
Rational("1/3") # => (1/3)
Rational(1, 3) # => (1/3)
Rational("0.1", "0.3") # => (1/3)
Rational(Complex(1,2), 2) # => ((1/2)+(1/1)*i)
//}
ただし、1.8系とは異なり、Rational オブジェクトは常に......約(それ以上
約分できない状態)である事に注意してください。
//emlist[例][ruby]{
Rational(2, 6) # => (1/3)
Rational(1, 3) * 3 # => (1/1)
//}
引数に文字列を指定する場合、以下のいずれかの形式で指定します。
* "1/3" のような分......Kernel.#Integer とは違い "0x10" のような進数を表す接頭
辞を含めた指定は行えません。
//emlist[例][ruby]{
Rational("1/3") # => (1/3)
Rational("0.3") # => (3/10)
Rational('0.3E0') # => (3/10)
Rational('0.1E1/3') # => (1/3)
Rational('1.2/3') # =>... -
Kernel
. # Rational(x , y = 1 , exception: true) -> Rational | nil (108.0) -
引数を有理数(Rational)に変換した結果を返します。
...onal オブジェクトを
返します。
//emlist[例][ruby]{
Rational("1/3") # => (1/3)
Rational(1, 3) # => (1/3)
Rational("0.1", "0.3") # => (1/3)
Rational(Complex(1,2), 2) # => ((1/2)+(1/1)*i)
//}
ただし、1.8系とは異なり、Rational オブジェクトは常に......約(それ以上
約分できない状態)である事に注意してください。
//emlist[例][ruby]{
Rational(2, 6) # => (1/3)
Rational(1, 3) * 3 # => (1/1)
//}
引数に文字列を指定する場合、以下のいずれかの形式で指定します。
* "1/3" のような分......Kernel.#Integer とは違い "0x10" のような進数を表す接頭
辞を含めた指定は行えません。
//emlist[例][ruby]{
Rational("1/3") # => (1/3)
Rational("0.3") # => (3/10)
Rational('0.3E0') # => (3/10)
Rational('0.1E1/3') # => (1/3)
Rational('1.2/3') # =>... -
Kernel
. # String(arg) -> String (108.0) -
引数を文字列(String)に変換した結果を返します。
...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
. # binding -> Binding (108.0) -
変数・メソッドなどの環境情報を含んだ Binding オブジェクトを 生成して返します。通常、Kernel.#eval の第二引数として使います。
...変数・メソッドなどの環境情報を含んだ Binding オブジェクトを
生成して返します。通常、Kernel.#eval の第二引数として使います。
//emlist[例][ruby]{
def foo
a = 1
binding
end
eval("p a", foo) #=> 1
//}
@see Kernel.#eval,Object::TOPLEVEL_BINDING...