るりまサーチ

最速Rubyリファレンスマニュアル検索!
143件ヒット [1-100件を表示] (0.024秒)
トップページ > クラス:Object[x] > クエリ:module[x] > クエリ:new[x]

別のキーワード

  1. module attr
  2. module constants
  3. module class_eval
  4. module module_eval

ライブラリ

検索結果

<< 1 2 > >>

Object#extend(*modules) -> self (167.0)

引数で指定したモジュールのインスタンスメソッドを self の特異 メソッドとして追加します。

...引数で指定したモジュールのインスタンスメソッドを self の特異
メソッドとして追加します。

Module
#include は、クラス(のインスタンス)に機能を追加します
が、extend は、ある特定のオブジェクトだけにモジュールの機能を...
...extend を行います。

@param modules モジュールを任意個指定します(クラスは不可)。
@return self を返します。

//emlist[][ruby]{
module
Foo
def a
'ok Foo'
end
end

module
Bar
def b
'ok Bar'
end
end

obj = Object.new
obj.extend Foo, Bar
p obj.a #=> "...
...tend Bar
end

p Klass.new.a #=> "ok Foo"
p Klass.b #=> "ok Bar"
//}

extend の機能は、「特異クラスに対する Module#include」
と言い替えることもできます。
ただしその場合、フック用のメソッド
Module#extended ではなく Module#included になると...

Object#respond_to?(name, include_all = false) -> bool (43.0)

オブジェクトがメソッド name を持つとき真を返します。

...されたメソッドで NotImplementedError が発生する場合は true を返します。

メソッドが定義されていない場合は、Object#respond_to_missing? を呼
び出してその結果を返します。

@param name Symbol または文字列で指定するメソッド名です。...
...ivate
def hello
"Guten Tag"
end
end
list = [F.new,D.new]

list.each{|it| puts it.hello if it.respond_to?(:hello)}
#=> Bonjour

list.each{|it| it.instance_eval("puts hello if it.respond_to?(:hello, true)")}
#=> Bonjour
# Guten Tag

module
Template
def main
start
template_method...
...mentedError.new
end

def finish
puts "finish"
end
end

class ImplTemplateMethod
include Template
def template_method
"implement template_method"
end
end

class NotImplTemplateMethod
include Template

# not implement template_method
end

puts ImplTemplateMethod.new.respond_to?...

Object#is_a?(mod) -> bool (37.0)

オブジェクトが指定されたクラス mod かそのサブクラスのインスタンスであるとき真を返します。

...返します。
Module
#includeだけではなく、Object#extendやModule#prependに
よってサブクラスのインスタンスになる場合も含みます。
上記のいずれでもない場合に false を返します。

@param mod クラスやモジュールなど、Moduleかそのサブ...
...です。

//emlist[][ruby]{
module
M
end
class C < Object
include M
end
class S < C
end

obj = S.new
p obj.is_a?(S) # true
p obj.is_a?(C) # true
p obj.is_a?(Object) # true
p obj.is_a?(M) # true
p obj.is_a?(Hash) # false
//}

@see Object#instance_of?,Module#===,Object#class...

Object#kind_of?(mod) -> bool (37.0)

オブジェクトが指定されたクラス mod かそのサブクラスのインスタンスであるとき真を返します。

...返します。
Module
#includeだけではなく、Object#extendやModule#prependに
よってサブクラスのインスタンスになる場合も含みます。
上記のいずれでもない場合に false を返します。

@param mod クラスやモジュールなど、Moduleかそのサブ...
...です。

//emlist[][ruby]{
module
M
end
class C < Object
include M
end
class S < C
end

obj = S.new
p obj.is_a?(S) # true
p obj.is_a?(C) # true
p obj.is_a?(Object) # true
p obj.is_a?(M) # true
p obj.is_a?(Hash) # false
//}

@see Object#instance_of?,Module#===,Object#class...

Object#instance_variables -> [Symbol] (25.0)

オブジェクトのインスタンス変数名をシンボルの配列として返します。

...列として返します。

//emlist[][ruby]{
obj = Object.new
obj.instance_eval { @foo, @bar = nil }
p obj.instance_variables

#=> [:@foo, :@bar]
//}

@see Object#instance_variable_get, Kernel.#local_variables, Kernel.#global_variables, Module.constants, Module#constants, Module#class_variables...

絞り込み条件を変える

Object#singleton_methods(inherited_too = true) -> [Symbol] (25.0)

そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返します。

...た特異メソッドとは Object#extend によって追加された特異メソッドや、
self がクラスの場合はスーパークラスのクラスメソッド(Classのインスタンスの特異メソッド)などです。

singleton_methods(false) は、Object#methods(false) と同じで...
...偽を指定します。

//emlist[例1][ruby]{
Parent = Class.new

class <<Parent
private; def private_class_parent() end
protected; def protected_class_parent() end
public; def public_class_parent() end
end

Foo = Class.new(Parent)

class <<Foo
private; def private_class_foo() end...
...cted; def protected_class_foo() end
public; def public_class_foo() end
end

module
Bar
private; def private_bar() end
protected; def protected_bar() end
public; def public_bar() end
end

obj = Foo.new
class <<obj
include Bar
private; def private_self() end
protected; d...

Object#enum_for(method = :each, *args) -> Enumerator (23.0)

Enumerator.new(self, method, *args) を返します。

...Enumerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module
Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repe...

Object#enum_for(method = :each, *args) {|*args| ... } -> Enumerator (23.0)

Enumerator.new(self, method, *args) を返します。

...Enumerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module
Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repe...

Object#to_enum(method = :each, *args) -> Enumerator (23.0)

Enumerator.new(self, method, *args) を返します。

...Enumerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module
Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repe...

Object#to_enum(method = :each, *args) {|*args| ... } -> Enumerator (23.0)

Enumerator.new(self, method, *args) を返します。

...Enumerator.new(self, method, *args) を返します。

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param args 呼び出...
...array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
module
Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repe...

絞り込み条件を変える

<< 1 2 > >>