るりまサーチ

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

別のキーワード

  1. _builtin define_method
  2. irb/input-method gets
  3. irb/input-method new
  4. irb/input-method encoding
  5. irb/input-method readable_atfer_eof?

検索結果

<< < 1 2 3 4 5 > >>

Module#public_class_method(names) -> self (12248.0)

name で指定したクラスメソッド (クラスの特異メソッド) の 可視性を public に変更します。

...0 個以上の String または Symbol を Array で指定します。

//emlist[例][ruby]{
class Foo
def self.foo
"foo"
end

private_class_method :foo
end

Foo.foo # NoMethodError: private method `foo' called for Foo:Class

Foo.public_class_method(:foo) # => Foo
Foo.foo # => "foo"
//}...

Module#alias_method(new, original) -> self (12240.0)

メソッドの別名を定義します。

...メソッドの別名を定義します。

//emlist[例][ruby]{
module
Kernel
alias_method :hoge, :puts # => Kernel
end
//}

alias との違いは以下の通りです。

* メソッド名は String または Symbol で指定します
* グローバル変数の別名をつけることはで...
...いメソッド名。String または Symbol で指定します。

@param original 元のメソッド名。String または Symbol で指定します。

@return self を返します。

@see d:spec/def#alias

//emlist[例][ruby]{
module
Kernel
alias_method :foo, :puts
end

foo "bar" # bar
//}...

Module#instance_methods(inherited_too = true) -> [Symbol] (12214.0)

そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返します。

...Object#methods

//emlist[例1][ruby]{
class Foo
private; def private_foo() end
protected; def protected_foo() end
public; def public_foo() end
end

# あるクラスのインスタンスメソッドの一覧を得る
p Foo.instance_methods(false)
p Foo.public_instance_methods(false)...
...p Foo.private_instance_methods(false)
p Foo.protected_instance_methods(false)

class Bar < Foo
end
//}

実行結果

[:protected_foo, :public_foo]
[:public_foo]
[:private_foo]
[:protected_foo]

//emlist[例2][ruby]{
class Bar
private; def private_foo() end
protected; de...
...stance_methods(true) - Object.instance_methods(true)
p Bar.public_instance_methods(true) - Object.public_instance_methods(true)
p Bar.private_instance_methods(true) - Object.private_instance_methods(true)
p Bar.protected_instance_methods(true) - Object.protected_instance_methods(true)...

Module#private_instance_methods(inherited_too = true) -> [Symbol] (12208.0)

そのモジュールで定義されている private メソッド名 の一覧を配列で返します。

...@see Object#private_methods, Module#instance_methods

//emlist[例][ruby]{
module
Foo
def foo; end
private def bar; end
end

module
Bar
include Foo

def baz; end
private def qux; end
end

Bar.private_instance_methods # => [:qux, :bar]
Bar.private_instance_methods(false) # => [:qux]
//}...

Module#ruby2_keywords(method_name, ...) -> nil (6619.0)

For the given method names, marks the method as passing keywords through a normal argument splat. This should only be called on methods that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the method such that if the method is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the method to other methods.

...For the given method names, marks the method as passing keywords through
a normal argument splat. This should only be called on methods that
accept an argument splat (`*args`) but not explicit keywords or a
keyword splat. It marks the method such that if the method is called
with keyword argument...
...other method call, and that method call does not include explicit
keywords or a keyword splat, the final element is interpreted as
keywords. In other words, keywords will be passed through the method to
other methods.

This should only be used for methods that delegate keywords to another
method
, an...
...ibility with Ruby versions before
2.7.

This method will probably be removed at some point, as it exists only
for backwards compatibility. As it does not exist in Ruby versions
before 2.7, check that the module responds to this method before calling
it. Also, be aware that if this method is removed,...

絞り込み条件を変える

Module#module_function() -> nil (26.0)

メソッドをモジュール関数にします。

...て返します。
引数なしの時は nil を返します。

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

=== 注意
module
_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プライベートメソッドとモ...
...ュール関数の別名は定義できません。

//emlist[例][ruby]{
module
M
def foo
p "foo"
end
module
_function :foo
alias bar foo
end

M.foo # => "foo"
M.bar # => undefined method `bar' for Foo:Module (NoMethodError)
//}

このコードでは、モジュール関数 foo と...
...付けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。

//emlist[例][ruby]{
module
M
def foo
p "foo"
end

alias bar foo
module
_function :foo, :bar
end

M.foo # => "foo"
M.bar # => "foo"
//}...

Module#module_function(*name) -> Array (26.0)

メソッドをモジュール関数にします。

...て返します。
引数なしの時は nil を返します。

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

=== 注意
module
_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プライベートメソッドとモ...
...ュール関数の別名は定義できません。

//emlist[例][ruby]{
module
M
def foo
p "foo"
end
module
_function :foo
alias bar foo
end

M.foo # => "foo"
M.bar # => undefined method `bar' for Foo:Module (NoMethodError)
//}

このコードでは、モジュール関数 foo と...
...付けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。

//emlist[例][ruby]{
module
M
def foo
p "foo"
end

alias bar foo
module
_function :foo, :bar
end

M.foo # => "foo"
M.bar # => "foo"
//}...

Module#module_function(name) -> String | Symbol (26.0)

メソッドをモジュール関数にします。

...て返します。
引数なしの時は nil を返します。

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

=== 注意
module
_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プライベートメソッドとモ...
...ュール関数の別名は定義できません。

//emlist[例][ruby]{
module
M
def foo
p "foo"
end
module
_function :foo
alias bar foo
end

M.foo # => "foo"
M.bar # => undefined method `bar' for Foo:Module (NoMethodError)
//}

このコードでは、モジュール関数 foo と...
...付けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。

//emlist[例][ruby]{
module
M
def foo
p "foo"
end

alias bar foo
module
_function :foo, :bar
end

M.foo # => "foo"
M.bar # => "foo"
//}...

Module#class_exec(*args) {|*vars| ... } -> object (20.0)

与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価します。

...[ruby]{
class Thing
end
c = 1

Thing.class_exec{
def hello()
"Hello there!"
end

define_method(:foo) do # ローカル変数がブロックの外側を参照している
c
end
}

t = Thing.new
p t.hello() #=> "Hello there!"
p t.foo() #=> 1
//}

@see Module...
...#module_eval, Module#class_eval...
<< < 1 2 3 4 5 > >>