156件ヒット
[101-156件を表示]
(0.070秒)
別のキーワード
ライブラリ
- ビルトイン (156)
キーワード
-
_ dump (12) - clone (12)
- dup (12)
-
initialize
_ clone (12) -
initialize
_ copy (12) -
initialize
_ dup (12) - inspect (12)
-
instance
_ variable _ defined? (12) -
instance
_ variable _ get (12) -
marshal
_ dump (12) -
singleton
_ method (12) -
to
_ s (12)
検索結果
先頭5件
-
Object
# instance _ variable _ defined?(var) -> bool (8.0) -
インスタンス変数 var が定義されていたら真を返します。
...s Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
p fred.instance_variable_defined?(:@a) #=> true
p fred.instance_variable_defined?("@b") #=> true
p fred.instance_variable_defined?("@c") #=> false
//}
@see Object#instance_variable_get,Object#instance_va... -
Object
# instance _ variable _ get(var) -> object | nil (8.0) -
オブジェクトのインスタンス変数の値を取得して返します。
...by]{
class Foo
def initialize
@foo = 1
end
end
obj = Foo.new
p obj.instance_variable_get("@foo") #=> 1
p obj.instance_variable_get(:@foo) #=> 1
p obj.instance_variable_get(:@bar) #=> nil
//}
@see Object#instance_variable_set,Object#instance_variables,Object#instance_variable_... -
Object
# marshal _ dump -> object (8.0) -
Marshal.#dump を制御するメソッドです。
...使うべきです。
@return 任意のオブジェクトで marshal_load の引数に利用できます。
//emlist[][ruby]{
class Foo
def initialize(arg)
@foo = arg
end
def marshal_dump
@foo
end
def marshal_load(obj)
p obj
@foo = obj
end
end
foo = Foo.new(['foo', 'bar......定義されていてもマーシャルできるようになります
(特異メソッドの情報が自動的に dump されるようになるわけではなく、
marshal_dump/marshal_load によりそれを実現する余地があるということです)。
@see Object#marshal_load, Marshal... -
Object
# singleton _ method(name) -> Method (8.0) -
オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。
...。
@raise NameError 定義されていないメソッド名を引数として与えると発生します。
//emlist[][ruby]{
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_metho......d(: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
# to _ s -> String (8.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...