138件ヒット
[1-100件を表示]
(0.031秒)
キーワード
- === (11)
-
enum
_ for (22) - initialize (11)
-
initialize
_ copy (11) -
public
_ send (22) -
respond
_ to? (11) - taint (6)
- tap (11)
-
to
_ enum (22) -
to
_ s (11)
検索結果
先頭5件
-
Object
# respond _ to?(name , include _ all = false) -> bool (46.0) -
オブジェクトがメソッド name を持つとき真を返します。
...されたメソッドで NotImplementedError が発生する場合は true を返します。
メソッドが定義されていない場合は、Object#respond_to_missing? を呼
び出してその結果を返します。
@param name Symbol または文字列で指定するメソッド名です。......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
finish
end
def start
puts "start"
end
def......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
# ===(other) -> bool (28.0) -
case 式で使用されるメソッドです。d:spec/control#case も参照してください。
...ドは case 式での振る舞いを考慮して、
各クラスの性質に合わせて再定義すべきです。
デフォルトでは内部で Object#== を呼び出します。
when 節の式をレシーバーとして === を呼び出すことに注意してください。
また Enumerable......"youth"
else
"adult"
end
puts result #=> "child"
def check arg
case arg
when /ruby(?!\s*on\s*rails)/i
"hit! #{arg}"
when String
"Instance of String class. But don't hit."
else
"unknown"
end
end
puts check([]) #=> unknown
puts check("mash-up in Ruby on Rails") #=......> instance of String class. But not hit...
puts check("<Ruby's world>") #=> hit! <Ruby's world>
//}
@see Object#==, Range#===, Module#===, Regexp#===, Enumerable#grep... -
Object
# tap {|x| . . . } -> self (28.0) -
self を引数としてブロックを評価し、self を返します。
...のメソッドの主目的です。
//emlist[][ruby]{
(1..10) .tap {|x| puts "original: #{x}" }
.to_a .tap {|x| puts "array: #{x}" }
.select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
.map {|x| x*x } .tap {|x| puts "squares: #{x}" }
//}......目的です。
//emlist[][ruby]{
(1..10) .tap {|x| puts "original: #{x}" }
.to_a .tap {|x| puts "array: #{x}" }
.select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
.map {|x| x*x } .tap {|x| puts "squares: #{x}" }
//}
@see Object#yield_self... -
Object
# initialize(*args , &block) -> object (16.0) -
ユーザ定義クラスのオブジェクト初期化メソッド。
...引数です。必須ではありません。
//emlist[][ruby]{
class Foo
def initialize name
puts "initialize Foo"
@name = name
end
end
class Bar < Foo
def initialize name, pass
puts "initialize Bar"
super name
@pass = pass
end
end
it = Bar.new('myname','0500')
p it
#... -
Object
# initialize _ copy(obj) -> object (16.0) -
(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。
...は self を obj の内容で置き換えます。ただ
し、self のインスタンス変数や特異メソッドは変化しません。
Object#clone, Object#dupの内部で使われています。
initialize_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに......alize_copy でコピーするよう定義しておくことで、dup や clone
を再定義する必要がなくなります。
デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェックを行い self
を返すだけのメソッドです。
initialize_copy と......Error レシーバが freeze されているか、obj のクラスがレシーバ
のクラスと異なる場合に発生します。
@see Object#clone,Object#dup
以下に例として、dup や clone がこのメソッドをどのように利用しているかを示します。
obj.dup は、... -
Object
# to _ s -> String (16.0) -
オブジェクトの文字列表現を返します。
...使って文字列に変換し
ます。
//emlist[][ruby]{
class Foo
def initialize num
@num = num
end
end
it = Foo.new(40)
puts it #=> #<Foo:0x2b69110>
class Foo
def to_s
"Class:Foo Number:#{@num}"
end
end
puts it #=> Class:Foo Number:40
//}
@see Object#to_str,Kernel.#String... -
Object
# enum _ for(method = :each , *args) -> Enumerator (10.0) -
Enumerator.new(self, method, *args) を返します。
...sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size... -
Object
# enum _ for(method = :each , *args) {|*args| . . . } -> Enumerator (10.0) -
Enumerator.new(self, method, *args) を返します。
...sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size... -
Object
# initialize _ copy(obj) -> object (10.0) -
(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。
...は self を obj の内容で置き換えます。ただ
し、self のインスタンス変数や特異メソッドは変化しません。
Object#clone, Object#dupの内部で使われています。
initialize_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに......alize_copy でコピーするよう定義しておくことで、dup や clone
を再定義する必要がなくなります。
デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェックを行い self
を返すだけのメソッドです。
initialize_copy と......Error レシーバが freeze されているか、obj のクラスがレシーバ
のクラスと異なる場合に発生します。
@see Object#clone,Object#dup
以下に例として、dup や clone がこのメソッドをどのように利用しているかを示します。
obj.dup は、... -
Object
# public _ send(name , *args) -> object (10.0) -
オブジェクトの public メソッド name を args を引数にして呼び出し、メソッ ドの実行結果を返します。
...しなかった場合に発生します。
@raise NoMethodError protected メソッドや private メソッドに対して実行
した場合に発生します。
//emlist[][ruby]{
1.public_send(:puts, "hello") # => NoMethodError
//}
@see BasicObject#__send__, Object#send... -
Object
# public _ send(name , *args) { . . . . } -> object (10.0) -
オブジェクトの public メソッド name を args を引数にして呼び出し、メソッ ドの実行結果を返します。
...しなかった場合に発生します。
@raise NoMethodError protected メソッドや private メソッドに対して実行
した場合に発生します。
//emlist[][ruby]{
1.public_send(:puts, "hello") # => NoMethodError
//}
@see BasicObject#__send__, Object#send...