22件ヒット
[1-22件を表示]
(0.419秒)
ライブラリ
- ビルトイン (22)
検索結果
先頭2件
-
Object
# define _ singleton _ method(symbol) { . . . } -> Symbol (26121.0) -
self に特異メソッド name を定義します。
...。
//emlist[][ruby]{
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello t... -
Object
# define _ singleton _ method(symbol , method) -> Symbol (26121.0) -
self に特異メソッド name を定義します。
...。
//emlist[][ruby]{
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello t...