176件ヒット
[1-100件を表示]
(0.034秒)
種類
- インスタンスメソッド (143)
- 定数 (33)
キーワード
- ARGF (11)
- DATA (11)
-
SCRIPT
_ LINES _ _ (11) - class (11)
- freeze (11)
- inspect (11)
-
instance
_ variables (11) - method (11)
- send (22)
-
singleton
_ method (11) -
to
_ a (11) -
to
_ ary (11) -
to
_ int (11) -
to
_ s (11) -
to
_ str (11)
検索結果
先頭5件
-
Object
# to _ s -> String (21.0) -
オブジェクトの文字列表現を返します。
...オブジェクトの文字列表現を返します。
Kernel.#print や Kernel.#sprintf は文字列以外の
オブジェクトが引数に渡された場合このメソッドを使って文字列に変換し
ます。
//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
# freeze -> self (15.0) -
オブジェクトを凍結(内容の変更を禁止)します。
...変数なら Kernel.#trace_var が使えます。
@return self を返します。
//emlist[][ruby]{
a1 = "foo".freeze
a1 = "bar"
p a1 #=> "bar"
a2 = "foo".freeze
a2.replace("bar") # can't modify frozen String (RuntimeError)
//}
凍結を解除することはできませんが、Object#dup を使......ます。
//emlist[][ruby]{
a = [1].freeze
p a.frozen? #=> true
a[0] = "foo"
p a # can't modify frozen Array (RuntimeError)
b = a.dup
p b #=> [1]
p b.frozen? #=> false
b[0] = "foo"
p b #=> ["foo"]
//}
@see Object#frozen?,Object#dup,Kernel.#trace_var......変数なら Kernel.#trace_var が使えます。
@return self を返します。
//emlist[][ruby]{
a1 = "foo".freeze
a1 = "bar"
p a1 #=> "bar"
a2 = "foo".freeze
a2.replace("bar") # can't modify frozen String (FrozenError)
//}
凍結を解除することはできませんが、Object#dup を使......ます。
//emlist[][ruby]{
a = [1].freeze
p a.frozen? #=> true
a[0] = "foo"
p a # can't modify frozen Array (FrozenError)
b = a.dup
p b #=> [1]
p b.frozen? #=> false
b[0] = "foo"
p b #=> ["foo"]
//}
@see Object#frozen?,Object#dup,Kernel.#trace_var... -
Object
# inspect -> String (15.0) -
オブジェクトを人間が読める形式に変換した文字列を返します。
...オブジェクトを人間が読める形式に変換した文字列を返します。
組み込み関数 Kernel.#p は、このメソッドの結果を使用して
オブジェクトを表示します。
//emlist[][ruby]{
[ 1, 2, 3..4, 'five' ].inspect # => "[1, 2, 3..4, \"five\"]"
Time.new.i......変数の名前、値の組を元にした文字列を返します。
//emlist[][ruby]{
class Foo
end
Foo.new.inspect # => "#<Foo:0x0300c868>"
class Bar
def initialize
@bar = 1
end
end
Bar.new.inspect # => "#<Bar:0x0300c868 @bar=1>"
//}
@see Kernel.#p... -
Object
# instance _ variables -> [Symbol] (15.0) -
オブジェクトのインスタンス変数名をシンボルの配列として返します。
...ンボルの配列として返します。
//emlist[][ruby]{
obj = Object.new
obj.instance_eval { @foo, @bar = nil }
p obj.instance_variables
#=> [:@foo, :@bar]
//}
@see Object#instance_variable_get, Kernel.#local_variables, Kernel.#global_variables, Module.constants, Module#constants, Module#cla... -
Object
:: DATA -> File (15.0) -
スクリプトの __END__ プログラムの終り以降をアクセスする File オブジェクト。
...標準入力から読みこまれなかった場合や、
__END__ で終っていない場合には定義されません。
* Kernel.#require や Kernel.#load で
読み込まれたファイルの中であってもそのファイル (__FILE__, d:spec/variables#pseudo)
ではな... -
Object
# class -> Class (9.0) -
レシーバのクラスを返します。
...レシーバのクラスを返します。
//emlist[][ruby]{
p "ruby".class #=> String
p 100.class #=> Integer
p ARGV.class #=> Array
p self.class #=> Object
p Class.class #=> Class
p Kernel.class #=> Module
//}
@see Class#superclass,Object#kind_of?,Object#instance_of?... -
Object
# method(name) -> Method (9.0) -
オブジェクトのメソッド name をオブジェクト化した Method オブジェクトを返します。
...ror 定義されていないメソッド名を引数として与えると発生します。
//emlist[][ruby]{
me = -365.method(:abs)
p me #=> #<Method: Integer#abs>
p me.call #=> 365
//}
@see Module#instance_method, Method, BasicObject#__send__, Object#send, Kernel.#eval, Object#singleton_method... -
Object
# send(name , *args) -> object (9.0) -
オブジェクトのメソッド name を args を引数に して呼び出し、メソッドの実行結果を返します。
...のメソッドを呼び出せます。
d:spec/def#limit も参照してください。
public メソッドだけ呼び出せれば良い場合は
Object#public_send を使う方が良いでしょう。
@param name 文字列かSymbol で指定するメソッド名です。
@param args 呼び出す......ーバは任意(Foo クラスのインスタンスである必要もない)
p Foo.new.send(methods[1]) # => "foo"
p Foo.new.send(methods[2]) # => "bar"
p Foo.new.send(methods[3]) # => "baz"
//}
@see Object#public_send, BasicObject#__send__, Object#method, Kernel.#eval, Proc, Method... -
Object
# send(name , *args) { . . . . } -> object (9.0) -
オブジェクトのメソッド name を args を引数に して呼び出し、メソッドの実行結果を返します。
...のメソッドを呼び出せます。
d:spec/def#limit も参照してください。
public メソッドだけ呼び出せれば良い場合は
Object#public_send を使う方が良いでしょう。
@param name 文字列かSymbol で指定するメソッド名です。
@param args 呼び出す......ーバは任意(Foo クラスのインスタンスである必要もない)
p Foo.new.send(methods[1]) # => "foo"
p Foo.new.send(methods[2]) # => "bar"
p Foo.new.send(methods[3]) # => "baz"
//}
@see Object#public_send, BasicObject#__send__, Object#method, Kernel.#eval, Proc, Method... -
Object
# singleton _ method(name) -> Method (9.0) -
オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。
...o.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_method(: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...