るりまサーチ

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

別のキーワード

  1. json to_json
  2. json state
  3. json parser
  4. json parse
  5. json generate

ライブラリ

キーワード

検索結果

<< < ... 14 15 16 17 18 > >>

Module#autoload(const_name, feature) -> nil (47.0)

定数 const_name を最初に参照した時に feature を Kernel.#require するように設定します。

...定数 const_name を最初に参照した時に feature を Kernel.#require するように設定します。

const_name が autoload 設定されていて、まだ定義されてない(ロードされていない)ときは、
autoload する対象を置き換えます。
const_name が(autoload...
...しません。

@param const_name String または Symbol で指定します。
なお、const_name には、"::" 演算子を含めることはできません。
つまり、self の直下に定義された定数しか指定できません。

@param feature Kernel.#require と同様...
...tmp/foo.rb ---------
class
Foo
class
Bar
end
end
# ----- end of /tmp/foo.rb ----

class
Foo
autoload :Bar, '/tmp/foo'
end
p
Foo::Bar #=> Foo::Bar
//}

以下のようにモジュールを明示的にレシーバとして呼び出すこともできます。

//emlist[例][ruby]{
# ------- /tmp/...

Object#class -> Class (43.0)

レシーバのクラスを返します。

...レシーバのクラスを返します。

//emlist[][ruby]{
p
"ruby".class #=> String
p
100.class #=> Integer
p
ARGV.class #=> Array
p
self.class #=> Object
p
Class.class #=> Class
p
Kernel.class #=> Module
//}

@see Class#superclass,Object#kind_of?,Object#instance_of?...

Module#constants(inherit = true) -> [Symbol] (37.0)

そのモジュール(またはクラス)で定義されている定数名の配列を返します。

...ません。

@param inherit true を指定するとスーパークラスや include したモジュールで
定義された定数が対象にはなります。false を指定した場合 対象にはなりません。

@see Module.constants, Kernel.#local_variables, Kernel.#global_variables...
...iables, Module#class_variables

//emlist[Module.constants と Module#constants の違い][ruby]{
# 出力の簡略化のため起動時の定数一覧を取得して後で差し引く
$clist = Module.constants

class
Foo
FOO = 1
end
class
Bar
BAR = 1

# Bar は BAR を含む
p
constants...
...# => [:BAR]
# 出力に FOO は含まれない
p
Module.constants - $clist # => [:BAR, :Bar, :Foo]
class
Baz
# Baz は定数を含まない
p
constants # => []

# ネストしたクラスでは、外側のクラスで定義した定...

Object#send(name, *args) -> object (37.0)

オブジェクトのメソッド name を args を引数に して呼び出し、メソッドの実行結果を返します。

...ドを呼び出せます。
d:spec/def#limit も参照してください。

p
ublic メソッドだけ呼び出せれば良い場合は
Object#public_send を使う方が良いでしょう。

@param name 文字列かSymbol で指定するメソッド名です。
@param args 呼び出すメソッド...
...に渡す引数です。

//emlist[][ruby]{
p
-365.send(:abs) #=> 365
p
"ruby".send(:sub,/./,"R") #=> "Ruby"


class
Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end

# 任意のキーとメソッド(の名前)の関係をハッシュに保持しておく
# レシーバの...
...ーバは任意(Foo クラスのインスタンスである必要もない)
p
Foo.new.send(methods[1]) # => "foo"
p
Foo.new.send(methods[2]) # => "bar"
p
Foo.new.send(methods[3]) # => "baz"
//}

@see Object#public_send, BasicObject#__send__, Object#method, Kernel.#eval, Proc, Method...

Object#send(name, *args) { .... } -> object (37.0)

オブジェクトのメソッド name を args を引数に して呼び出し、メソッドの実行結果を返します。

...ドを呼び出せます。
d:spec/def#limit も参照してください。

p
ublic メソッドだけ呼び出せれば良い場合は
Object#public_send を使う方が良いでしょう。

@param name 文字列かSymbol で指定するメソッド名です。
@param args 呼び出すメソッド...
...に渡す引数です。

//emlist[][ruby]{
p
-365.send(:abs) #=> 365
p
"ruby".send(:sub,/./,"R") #=> "Ruby"


class
Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end

# 任意のキーとメソッド(の名前)の関係をハッシュに保持しておく
# レシーバの...
...ーバは任意(Foo クラスのインスタンスである必要もない)
p
Foo.new.send(methods[1]) # => "foo"
p
Foo.new.send(methods[2]) # => "bar"
p
Foo.new.send(methods[3]) # => "baz"
//}

@see Object#public_send, BasicObject#__send__, Object#method, Kernel.#eval, Proc, Method...

絞り込み条件を変える

Module#ancestors -> [Class, Module] (31.0)

クラス、モジュールのスーパークラスとインクルードしているモジュール を優先順位順に配列に格納して返します。

...先順位順に配列に格納して返します。

//emlist[例][ruby]{
module Foo
end
class
Bar
include Foo
end
class
Baz < Bar
p
ancestors
p
included_modules
p
superclass
end
# => [Baz, Bar, Foo, Object, Kernel, BasicObject]
# => [Foo, Kernel]
# => Bar
//}

@see Module#included_modules...

Module#const_defined?(name, inherit = true) -> bool (31.0)

モジュールに name で指定される名前の定数が定義されている時真 を返します。

...とができます。

@param name String, Symbol で指定される定数名。

@param inherit false を指定するとスーパークラスや include したモジュールで
定義された定数は対象にはなりません。

//emlist[例][ruby]{
module Kernel
FOO = 1
end

# Object...
...ールの定数に対しても
# true を返す
p
Object.const_defined?(:FOO) # => true

module Bar
BAR = 1
end
class
Object
include Bar
end
# ユーザ定義のモジュールに対しても同様
p
Object.const_defined?(:BAR) # => true

class
Baz
include Bar
end
# Object 以外でも同...
...様になった
# 第二引数のデフォルト値が true であるため
p
Baz.const_defined?(:BAR) # => true

# 第二引数を false にした場合
p
Baz.const_defined?(:BAR, false) # => false
//}...

Thread#exit -> self (31.0)

スレッドの実行を終了させます。終了時に ensure 節が実行されます。

...スを Kernel.#exit(0)
により終了します。

Kernel
.#exit と違い例外 SystemExit を発生しません。

th1 = Thread.new do
begin
sleep 10
ensure
p
"this will be displayed"
end
end

sleep 0.1
th1.kill

#=> "this will be displayed"

@see Kernel.#exit,...

Thread#kill -> self (31.0)

スレッドの実行を終了させます。終了時に ensure 節が実行されます。

...スを Kernel.#exit(0)
により終了します。

Kernel
.#exit と違い例外 SystemExit を発生しません。

th1 = Thread.new do
begin
sleep 10
ensure
p
"this will be displayed"
end
end

sleep 0.1
th1.kill

#=> "this will be displayed"

@see Kernel.#exit,...
<< < ... 14 15 16 17 18 > >>