るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

検索結果

<< 1 2 > >>

Object#methods(include_inherited = true) -> [Symbol] (18282.0)

そのオブジェクトに対して呼び出せるメソッド名の一覧を返します。 このメソッドは public メソッドおよび protected メソッドの名前を返します。

...ect#singleton_methods(false) と同じになっています。


@param include_inherited 引数が偽の時は Object#singleton_methods(false) と同じになります。

//emlist[例1][ruby]{
class Parent
private; def private_parent() end
protected; def protected_parent() end
public;...
...def public_parent() end
end


class Foo < Parent
private; def private_foo() end
protected; def protected_foo() end
public; def public_foo() end
end


obj = Foo.new
class <<obj
private; def private_singleton() end
protected; def protected_singleton() end
public; de...
...f public_singleton() end
end


# あるオブジェクトの応答できるメソッドの一覧を得る。
p obj.methods(false)
p obj.public_methods(false)
p obj.private_methods(false)
p obj.protected_methods(false)

# 実行結果
[:protected_singleton, :public_singleton]
[:public_singleton, :p...

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

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

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

singleton_methods(false) は、Object#methods(false) と同じです。

@p...
...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
protected; def protected_class_foo() end...
...o() 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; def protected_self() end
public; def public_self() end
end


#...

Module#instance_methods(inherited_too = true) -> [Symbol] (6246.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)...
...e_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; def protected_foo() end...
..._foo() end
end


# あるクラスのインスタンスメソッドの一覧を得る。
# 親のクラスのインスタンスメソッドも含めるため true を指定して
# いるが、Object のインスタンスメソッドは一覧から排除している。
p Bar.instance_methods(true)...

Module#ruby2_keywords(method_name, ...) -> nil (6182.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.

...e 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...
...o
other methods.

This should only be used for methods that delegate keywords to another
method, and only for backwards compatibility 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 versio...
...aware that if this method is removed, the behavior of the
method will change so that it does not pass through keywords.

//emlist[例][ruby]{
module Mod
def foo(meth, *args, &block)
send(:"do_#{meth}", *args, &block)
end

ruby
2_keywords(:foo) if respond_to?(:ruby2_keywords, true)
end

//}...

Refinement#import_methods(*modules) -> self (6174.0)

モジュールからメソッドをインポートします。

...ートします。

Module#includeと違って、import_methods はメソッドをコピーして
refinement に追加して、refinementでインポートしたメソッドを有効化します。

メソッドをコピーするため、Rubyコードで定義されたメソッドだけしか
イン...
...[ruby]{
module StrUtils
def indent(level)
' ' * level + self
end

end


module M
refine String do
import_methods StrUtils
end

end


using M
p "foo".indent(3) # => " foo"

module M
refine String do
import_methods Enumerable
# Can't import method which is not defined with Ruby...
...code: Enumerable#drop
end

end

//}...

絞り込み条件を変える

Module#private_instance_methods(inherited_too = true) -> [Symbol] (6168.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]
//}...

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

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

...クもそのまま引き渡します。

send が再定義された場合に備えて別名 __send__ も
用意されており、ライブラリではこちらを使うべきです。また
__send__ は再定義すべきではありません。

send, __send__ は、メソッドの呼び出し制限...
...lic_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
d...
...ef bar() "bar" end
def baz() "baz" end
end


# 任意のキーとメソッド(の名前)の関係をハッシュに保持しておく
# レシーバの情報がここにはないことに注意
methods
= {1 => :foo,
2 => :bar,
3 => :baz}

# キーを使って関連するメソッドを呼び出...

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

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

...クもそのまま引き渡します。

send が再定義された場合に備えて別名 __send__ も
用意されており、ライブラリではこちらを使うべきです。また
__send__ は再定義すべきではありません。

send, __send__ は、メソッドの呼び出し制限...
...lic_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
d...
...ef bar() "bar" end
def baz() "baz" end
end


# 任意のキーとメソッド(の名前)の関係をハッシュに保持しておく
# レシーバの情報がここにはないことに注意
methods
= {1 => :foo,
2 => :bar,
3 => :baz}

# キーを使って関連するメソッドを呼び出...

Proc#ruby2_keywords -> proc (6160.0)

Marks the proc as passing keywords through a normal argument splat. This should only be called on procs that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the proc such that if the proc 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 proc to other methods.

...to other methods.

This should only be used for procs that delegate keywords to another
method, and only for backwards compatibility 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 version...
...so, be aware that if this method is removed, the behavior of the
proc will change so that it does not pass through keywords.

//emlist[][ruby]{
module Mod
foo = ->(meth, *args, &block) do
send(:"do_#{meth}", *args, &block)
end

foo.ruby2_keywords if foo.respond_to?(:ruby2_keywords)
end

//}...

JSON::Generator::GeneratorMethods::Object#to_json(state_or_hash = nil) -> String (3019.0)

自身を to_s で文字列にした結果を JSON 形式の文字列に変換して返します。

...t[例][ruby]{
require "json"

class Person
attr :name, :age

def initialize(name, age)
@name, @age = name, age
end

end


tanaka = Person.new("tanaka", 29)

tanaka.to_json # => "\"#<Person:0x00007ffdec0167c8>\""
tanaka.method(:to_json).owner # => JSON::Ext::Generator::GeneratorMethods::Objec...

絞り込み条件を変える

<< 1 2 > >>