るりまサーチ

最速Rubyリファレンスマニュアル検索!
453件ヒット [101-200件を表示] (0.027秒)
トップページ > クラス:Object[x] > クエリ:Class[x]

別のキーワード

  1. argf.class lines
  2. argf.class each
  3. argf.class each_line
  4. class new
  5. argf.class gets

検索結果

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

Object#define_singleton_method(symbol, method) -> Symbol (25.0)

self に特異メソッド name を定義します。

...す。

@return メソッド名を表す Symbol を返します。

//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(:hel...

Object#instance_of?(klass) -> bool (25.0)

オブジェクトがクラス klass の直接のインスタンスである時真を返します。

...常に obj.kind_of?(c) も成立します。

@param klass Classかそのサブクラスのインスタンスです。

//emlist[][ruby]{
class
C < Object
end
class
S < C
end

obj = S.new
p obj.instance_of?(S) # true
p obj.instance_of?(C) # false
//}

@see Object#kind_of?,Object#class...

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

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

...されたメソッドで NotImplementedError が発生する場合は true を返します。

メソッドが定義されていない場合は、Object#respond_to_missing? を呼
び出してその結果を返します。

@param name Symbol または文字列で指定するメソッド名です。...
...す。省略した場合
は false(含めない) を指定した事になります。

//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...
...ate_method
raise NotImplementedError.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 ImplT...

Object#to_s -> String (25.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#is_a?(mod) -> bool (19.0)

オブジェクトが指定されたクラス mod かそのサブクラスのインスタンスであるとき真を返します。

...ードしたクラスかそのサブクラス
のインスタンスである場合にも真を返します。
Module#includeだけではなく、Object#extendやModule#prependに
よってサブクラスのインスタンスになる場合も含みます。
上記のいずれでもない場合に fa...
...です。

//emlist[][ruby]{
module M
end
class
C < Object
include M
end
class
S < C
end

obj = S.new
p obj.is_a?(S) # true
p obj.is_a?(C) # true
p obj.is_a?(Object) # true
p obj.is_a?(M) # true
p obj.is_a?(Hash) # false
//}

@see Object#instance_of?,Module#===,Object#class...

絞り込み条件を変える

Object#kind_of?(mod) -> bool (19.0)

オブジェクトが指定されたクラス mod かそのサブクラスのインスタンスであるとき真を返します。

...ードしたクラスかそのサブクラス
のインスタンスである場合にも真を返します。
Module#includeだけではなく、Object#extendやModule#prependに
よってサブクラスのインスタンスになる場合も含みます。
上記のいずれでもない場合に fa...
...です。

//emlist[][ruby]{
module M
end
class
C < Object
include M
end
class
S < C
end

obj = S.new
p obj.is_a?(S) # true
p obj.is_a?(C) # true
p obj.is_a?(Object) # true
p obj.is_a?(M) # true
p obj.is_a?(Hash) # false
//}

@see Object#instance_of?,Module#===,Object#class...

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

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

...

ただし特別に、引数が偽の時は Object#singleton_methods(false) と同じになっています。


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

//emlist[例1][ruby]{
class
Parent
private; def private_parent() end...
...; 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 p...
...指定して
# いるが、Object のインスタンスメソッドは一覧から排除している。
p obj.methods(true) - Object.instance_methods(true)
p obj.public_methods(true) - Object.public_instance_methods(true)
p obj.private_methods(true) - Object.private_instance_methods(t...

Object.yaml_tag(tag) -> () (19.0)

クラスと tag の間を関連付けます。

...'

class
Foo
def initialize(x)
@x = x
end

attr_reader :x
end

# Dumps Ruby object normally
p Psych.dump(Foo.new(3))
# =>
# --- !ruby/object:Foo
# x: 3

# Registers tag with class Foo
Foo.yaml_as("tag:example.com,2013:foo")
# ... and dumps the object...
...of Foo class
Psych.dump(Foo.new(3), STDOUT)
# =>
# --- !<tag:example.com,2013:foo>
# x: 3

# Loads the object from the tagged YAML node
p Psych.load(<<EOS)
--- !<tag:example.com,2012:foo>
x: 8
EOS
# => #<Foo:0x0000000130f48 @x=8>...

Object#===(other) -> bool (13.0)

case 式で使用されるメソッドです。d:spec/control#case も参照してください。

...ドは case 式での振る舞いを考慮して、
各クラスの性質に合わせて再定義すべきです。

デフォルトでは内部で Object#== を呼び出します。

when 節の式をレシーバーとして === を呼び出すことに注意してください。

また Enumerable...
...n 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#===, Rege...

Object#_dump(limit) -> String (13.0)

Marshal.#dump において出力するオブジェクトがメソッド _dump を定義している場合には、そのメソッドの結果が書き出されます。

...ッド _dump
を定義している場合には、そのメソッドの結果が書き出されます。

バージョン1.8.0以降ではObject#marshal_dump, Object#marshal_loadの使用
が推奨されます。 Marshal.dump するオブジェクトが _dump と marshal_dump の両方の
メソッ...
...ベルを表す整数です。
@return オブジェクトを文字列化したものを返すように定義すべきです。

//emlist[][ruby]{
class
Foo
def initialize(arg)
@foo = arg
end
def _dump(limit)
Marshal.dump(@foo, limit)
end
def self._load(obj)
p obj
Foo.new(Ma...
...い場合や拡張ライブラリで定義し
たクラスのインスタンスがインスタンス変数以外に情報を保持する場合に
利用します。(例えば、クラス Time は、_dump/_load を定義して
います)

@see Object#marshal_dump, Object#marshal_load, Class#_load...

絞り込み条件を変える

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