るりまサーチ

最速Rubyリファレンスマニュアル検索!
444件ヒット [101-200件を表示] (0.131秒)

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

検索結果

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

Object#define_singleton_method(symbol) { ... } -> Symbol (6138.0)

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

...を String または Symbol で指定します。

@param method Proc、Method あるいは UnboundMethod の
いずれかのインスタンスを指定します。

@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(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
//}...

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

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

...を String または Symbol で指定します。

@param method Proc、Method あるいは UnboundMethod の
いずれかのインスタンスを指定します。

@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(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
//}...

Object#extend(*modules) -> self (6138.0)

引数で指定したモジュールのインスタンスメソッドを self の特異 メソッドとして追加します。

...ス)に機能を追加します
が、extend は、ある特定のオブジェクトだけにモジュールの機能を追加
したいときに使用します。

引数に複数のモジュールを指定した場合、最後
の引数から逆順に extend を行います。

@param modules モ...
...クラスは不可)。
@return self を返します。

//emlist[][ruby]{
module Foo
def a
'ok Foo'
end
end

module Bar
def b
'ok Bar'
end
end

obj = Object.new
obj.extend Foo, Bar
p obj.a #=> "ok Foo"
p obj.b #=> "ok Bar"

class
Klass
include Foo
extend Bar
end

p Klass.new.a...
...//}

extend の機能は、「特異クラスに対する Module#include」
と言い替えることもできます。
ただしその場合、フック用のメソッド
が Module#extended ではなく Module#included になるという違いがあります。

//emlist[][ruby]{
# obj.extend Foo,...

Object#inspect -> String (6138.0)

オブジェクトを人間が読める形式に変換した文字列を返します。

...の結果を使用して
オブジェクトを表示します。

//emlist[][ruby]{
[ 1, 2, 3..4, 'five' ].inspect # => "[1, 2, 3..4, \"five\"]"
T
ime.new.inspect # => "2008-03-08 19:43:39 +0900"
//}

inspect メソッドをオーバーライドしなかった場合、クラス名...
...変数の名前、値の組を元にした文字列を返します。

//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_of?(klass) -> bool (6138.0)

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

...

obj.instance_of?(c) が成立する時には、常に 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#to_s -> String (6138.0)

オブジェクトの文字列表現を返します。

...rint や 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#remove_instance_variable(name) -> object (6126.0)

オブジェクトからインスタンス変数 name を取り除き、そのインス タンス変数に設定されていた値を返します。

...ない場合に発生します。

//emlist[][ruby]{
class
Foo
def foo
@foo = 1
p remove_instance_variable(:@foo) #=> 1
p remove_instance_variable(:@foo) # instance variable @foo not defined (NameError)
end
end
Foo.new.foo
//}

@see Module#remove_class_variable,Module#remove_const...

Object#instance_variable_defined?(var) -> bool (6120.0)

インスタンス変数 var が定義されていたら真を返します。

...ist[][ruby]{
class
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,O...
...bject#instance_variable_set,Object#instance_variables...

Object#instance_variable_get(var) -> object | nil (6120.0)

オブジェクトのインスタンス変数の値を取得して返します。

...mlist[][ruby]{
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...
<< < 1 2 3 4 ... > >>