るりまサーチ

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

別のキーワード

  1. module attr
  2. module public
  3. module private
  4. module protected
  5. module new

ライブラリ

検索結果

<< < 1 2 3 >>

Object#singleton_method(name) -> Method (8.0)

オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。

...o.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_method(:hi) # => #<Method: #<Demo:0xf8b0c3c4 @iv=99>.hi>
m.call #=> "Hi, @iv = 99"
m = k.singleton_method(:hello) # => NameError
//}

@see Module#instance_method, Method, BasicObject#__send__, Object#send, Kernel.#eval, Object#method...

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

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

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

singleton_methods(false) は、Object#methods(false) と同じで...
...rent)

class <<Foo
private; def private_class_foo() end
protected; 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...
...ラスのクラスメソッドも含まれるよう true を指定したが、
# Object のクラスメソッドは一覧から排除している。

p obj.singleton_methods(true)
p Foo.singleton_methods(true) - Object.singleton_methods(true)

#実行結果

[:protected_self, :public_self, :protecte...

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

Enumerator.new(self, method, *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 (8.0)

Enumerator.new(self, method, *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 3 >>