るりまサーチ

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

別のキーワード

  1. _builtin inspect
  2. _builtin []
  3. _builtin to_s
  4. _builtin each

モジュール

キーワード

検索結果

<< < 1 2 3 4 5 ... > >>

File::Stat#<=>(o) -> Integer | nil (8033.0)

ファイルの最終更新時刻を比較します。self が other よりも 新しければ正の数を、等しければ 0 を古ければ負の数を返します。 比較できない場合は nil を返します。

...fp1 = Tempfile.open("first")
fp1.print "古い方\n"
sleep(1)
fp2 = Tempfile.open("second")
fp2.print "新しい方\n"

p File::Stat.new(fp1.path) <=> File::Stat.new(fp2.path) #=> -1
p File::Stat.new(fp2.path) <=> File::Stat.new(fp1.path) #=> 1
p File::Stat.new(fp1.path) <=> fp2.path #=> nil
//}...

Object#respond_to?(name, include_all = false) -> bool (8033.0)

オブジェクトがメソッド name を持つとき真を返します。

...なります。

//emlist[][ruby]{
class F
def hello
"Bonjour"
end
end

class D
private
def hello
"Guten Tag"
end
end
list = [F.new,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, tru...
...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?...
...emplate_method) # => true
# NotImplementedError が発生しているが、Rubyによる実装部のため true を返す
puts NotImplTemplateMethod.new.respond_to?(:template_method) # => true
# GNU/Linux で実行。C言語による実装部のため false を返す
puts File.respond_to?(:lchmod)...

Struct#to_h -> Hash (8033.0)

self のメンバ名(Symbol)と値の組を Hash にして返します。

...self のメンバ名(Symbol)と値の組を Hash にして返します。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h
# => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}
//}

ブロックを...
...ックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :addr...
...ess=>"123 Maple, Anytown NC123 Maple, Anytown NC", :zip=>24690}
//}

[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。...

Struct#to_h {|member, value| block } -> Hash (8033.0)

self のメンバ名(Symbol)と値の組を Hash にして返します。

...self のメンバ名(Symbol)と値の組を Hash にして返します。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h
# => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}
//}

ブロックを...
...ックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :addr...
...ess=>"123 Maple, Anytown NC123 Maple, Anytown NC", :zip=>24690}
//}

[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。...

TracePoint#defined_class -> Class | module (8033.0)

メソッドを定義したクラスかモジュールを返します。

...クラスかモジュールを返します。

//emlist[例][ruby]{
class C; def foo; end; end
trace = TracePoint.new(:call) do |tp|
p tp.defined_class # => C
end.enable do
C.new.foo
end
//}

メソッドがモジュールで定義されていた場合も(include に関係なく)モジュー
...
...例][ruby]{
module M; def foo; end; end
class C; include M; end;
trace = TracePoint.new(:call) do |tp|
p tp.defined_class # => M
end.enable do
C.new.foo
end
//}

[注意] 特異メソッドを実行した場合は TracePoint#defined_class は特異クラ
スを返します。また、Kernel.#set...
...ラメータは特異クラスではなく元のクラスを返します。

//emlist[例][ruby]{
class C; def self.foo; end; end
trace = TracePoint.new(:call) do |tp|
p tp.defined_class # => #<Class:C>
end.enable do
C.foo
end
//}

Kernel.#set_trace_func と TracePoint の上記の差分に注...

絞り込み条件を変える

Module#inspect -> String (8027.0)

モジュールやクラスの名前を文字列で返します。

...lass C
end
end

p A.name #=> "A"
p A::B.name #=> "A::B"
p A::C.name #=> "A::C"

# 名前のないモジュール / クラス
p Module.new.name #=> nil
p Class.new.name #=> nil
p Module.new.to_s #=> "#<Module:0x00007f90b09112c8>"
p Class.new.to_s #=> "#<Class:0x00007fa5c40b41b0>"
//}...

Module#name -> String | nil (8027.0)

モジュールやクラスの名前を文字列で返します。

...lass C
end
end

p A.name #=> "A"
p A::B.name #=> "A::B"
p A::C.name #=> "A::C"

# 名前のないモジュール / クラス
p Module.new.name #=> nil
p Class.new.name #=> nil
p Module.new.to_s #=> "#<Module:0x00007f90b09112c8>"
p Class.new.to_s #=> "#<Class:0x00007fa5c40b41b0>"
//}...

Module#to_s -> String (8027.0)

モジュールやクラスの名前を文字列で返します。

...lass C
end
end

p A.name #=> "A"
p A::B.name #=> "A::B"
p A::C.name #=> "A::C"

# 名前のないモジュール / クラス
p Module.new.name #=> nil
p Class.new.name #=> nil
p Module.new.to_s #=> "#<Module:0x00007f90b09112c8>"
p Class.new.to_s #=> "#<Class:0x00007fa5c40b41b0>"
//}...

Object#initialize(*args, &block) -> object (8027.0)

ユーザ定義クラスのオブジェクト初期化メソッド。

...このメソッドは Class#new から新しく生成されたオブ
ジェクトの初期化のために呼び出されます。他の言語のコンストラクタに相当します。
デフォルトの動作ではなにもしません。

initialize には
Class#new に与えられた引数が...
...nitialize 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
#=> initialize Bar
# initialize Foo
# #<Bar:0x2b68f08 @name="myname", @pass="0500">
//}

@see Class#new...

Struct#==(other) -> bool (8027.0)

self と other のクラスが同じであり、各メンバが == メソッドで比較して等しい場合に true を返します。そうでない場合に false を返します。

...ます。

@param other self と比較したいオブジェクトを指定します。

//emlist[例][ruby]{
Dog = Struct.new(:name, :age)
dog1 = Dog.new("fred", 5)
dog2 = Dog.new("fred", 5)

p dog1 == dog2 #=> true
p dog1.eql?(dog2) #=> true
p dog1.equal?(dog2)...
...#=> false
//}

[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

@see Struct#eql?...

絞り込み条件を変える

Struct#eql?(other) -> bool (8027.0)

self と other のクラスが同じであり、各メンバが eql? メソッドで比較して等しい場合に true を返します。そうでない場合に false を返します。

...ます。

@param other self と比較したいオブジェクトを指定します。

//emlist[例][ruby]{
Dog = Struct.new(:name, :age)
dog1 = Dog.new("fred", 5)
dog2 = Dog.new("fred", 5)

p dog1 == dog2 #=> true
p dog1.eql?(dog2) #=> true
p dog1.equal?(dog2)...
...#=> false
//}

[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

@see Struct#==...
<< < 1 2 3 4 5 ... > >>