るりまサーチ

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

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

検索結果

<< < 1 2 3 >>

Module#include(*mod) -> self (151.0)

モジュール mod をインクルードします。

...ドします。

@
param mod Module のインスタンス( Enumerable など)を指定します。

@
raise ArgumentError 継承関係が循環してしまうような include を行った場合に発生します。

//emlist[例][ruby]{
module
M
end
module
M2
include M
end
module
M
include M2
end...
...き継ぐことです。
インクルードは多重継承の代わりに用いられており、 mix-in とも呼びます。

//emlist[例][ruby]{
class
C
include FileTest
include Math
end

p C.ancestors

# => [C, Math, FileTest, Object, Kernel]
//}

モジュールの機能追加は、クラ...
...先に行われます
(上の例の Module#ancestors の結果がメソッド探索の順序です)。

同じモジュールを二回以上 include すると二回目以降は無視されます。

//emlist[例][ruby]{
module
M
end
class
C1
include M
end
class
C2 < C1
include M # この incl...

Module#private_constant(*name) -> self (151.0)

name で指定した定数の可視性を private に変更します。

...す。

@
param name 0 個以上の String か Symbol を指定します。

@
raise NameError 存在しない定数を指定した場合に発生します。

@
return self を返します。

@
see Module#public_constant, Object#untrusted?

//emlist[例][ruby]{
module
Foo
BAR = 'bar'
class
Baz; en...
...d
QUX = 'qux'
class
Quux; end

private_constant :QUX
private_constant :Quux
end

Foo::BAR # => "bar"
Foo::Baz # => Foo::Baz
Foo::QUX # => NameError: private constant Foo::QUX referenced
Foo::Quux # => NameError: private constant Foo::Quux referenced
//}...
...

@
param name 0 個以上の String か Symbol を指定します。

@
raise NameError 存在しない定数を指定した場合に発生します。

@
return self を返します。

@
see Module#public_constant

//emlist[例][ruby]{
module
Foo
BAR = 'bar'
class
Baz; end
QUX = 'qux'
class
Q...

Module#public_constant(*name) -> self (145.0)

name で指定した定数の可視性を public に変更します。

...lic に変更します。

@
param name 0 個以上の String か Symbol を指定します。

@
raise NameError 存在しない定数を指定した場合に発生します。

@
return self を返します。

//emlist[例][ruby]{
module
SampleModule
class
SampleInnerClass
end

# => 非公開...
...nerClass
end

begin
SampleModule::SampleInnerClass
rescue => e
e # => #<NameError: private constant SampleModule::SampleInnerClass referenced>
end

module
SampleModule
# => 非公開クラスであることは承知で利用するために public にする
public_constant :SampleInnerClass
e...
...nd

SampleModule::SampleInnerClass # => SampleModule::SampleInnerClass
//}

@
see Module#private_constant, Object#untrusted?...
...nd

SampleModule::SampleInnerClass # => SampleModule::SampleInnerClass
//}

@
see Module#private_constant...

Module#remove_method(*name) -> self (139.0)

インスタンスメソッド name をモジュールから削除します。

...す。

Ruby
1.8.0 以降は複数のメソッド名を指定して一度に削除できます。

@
param name 0 個以上の String か Symbol を指定します。

@
raise NameError 指定したメソッドが定義されていない場合に発生します。

//emlist[例][ruby]{
class
C
def f...
...oo
end

remove_method :foo
remove_method :no_such_method # 例外 NameError が発生
end
//}

@
see Module#undef_method...

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

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

...きは何もしません。

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

@
param feature Kernel.#requi...
...ruby]{
# ------- /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...
...----
class
Foo
class
Bar
end
end
# ----- end of /tmp/foo.rb ----

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

以下のように、autoload したライブラリがネストした定数を定義しない場
合、NameError が発生します。

//emlist[例][ruby]{...

絞り込み条件を変える

Module#<(other) -> bool | nil (76.0)

比較演算子。self が other の子孫である場合、 true を返します。 self が other の先祖か同一のクラス/モジュールである場合、false を返します。

...比較演算子。self が other の子孫である場合、 true を返します。
self
が other の先祖か同一のクラス/モジュールである場合、false を返します。

継承関係にないクラス同士の比較では
nil を返します。

@
param other 比較対象のモ...
...ジュールやクラス

@
raise TypeError other がクラスやモジュールではない場合に発生します。

//emlist[例][ruby]{
module
Foo
end
class
Bar
include Foo
end
class
Baz < Bar
end
class
Qux
end
p Bar < Foo # => true
p Baz < Bar # => true
p Baz < Foo # => true
p Ba...
...z < Qux # => nil
p Baz > Qux # => nil

p Foo < Object.new # => in `<': compared with non class/module (TypeError)
//}...

Module#<=>(other) -> Integer | nil (66.0)

self と other の継承関係を比較します。

...
self
と other の継承関係を比較します。

self
と other を比較して、
self
が other の子孫であるとき -1、
同一のクラス/モジュールのとき 0、
self
が other の先祖であるとき 1
を返します。

継承関係にないクラス同士の比較では
n...
...other がクラスやモジュールでなければ
nil を返します。

@
param other 比較対象のクラスやモジュール

//emlist[例][ruby]{
module
Foo
end
class
Bar
include Foo
end
class
Baz < Bar
end
class
Qux
end
p Bar <=> Foo # => -1
p Baz <=> Bar # => -1
p Baz <=> Foo...

Module#instance_method(name) -> UnboundMethod (60.0)

self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。

...
self
のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。

@
param name メソッド名を Symbol または String で指定します。

@
raise NameError self に存在しないメソッドを指定した場合に発生します。

@
see Module#publ...
...ic_instance_method, Object#method

//emlist[例][ruby]{
class
Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end
def do_e() print "!\n"; end
def do_v() print "Dave"; end
Dispatcher = {
"a" => instance_method(:do_a),
"d" => instance_method(:do_d),...
..."e" => instance_method(:do_e),
"v" => instance_method(:do_v)
}
def interpret(string)
string.each_char {|b| Dispatcher[b].bind(self).call }
end
end

interpreter = Interpreter.new
interpreter.interpret('dave')
# => Hello there, Dave!
//}...

Module#include?(mod) -> bool (42.0)

self かその親クラス / 親モジュールがモジュール mod を インクルードしていれば true を返します。

...
self
かその親クラス / 親モジュールがモジュール mod を
インクルードしていれば true を返します。

@
param mod Module を指定します。

//emlist[例][ruby]{
module
M
end
class
C1
include M
end
class
C2 < C1
end

p C1.include?(M) # => true
p C2.include?(M)...
<< < 1 2 3 >>