るりまサーチ

最速Rubyリファレンスマニュアル検索!
277件ヒット [1-100件を表示] (0.127秒)
トップページ > クエリ:I[x] > クエリ:ruby[x] > クエリ:u[x] > クエリ:define[x]

別のキーワード

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

検索結果

<< 1 2 3 > >>

ObjectSpace.#undefine_finalizer(obj) -> object (24418.0)

obj に対するファイナライザをすべて解除します。 obj を返します。

...emlist[例][ruby]{
class Sample
def Sample.callback
proc {
puts "finalize"
}
end

def initialize
ObjectSpace.define_finalizer(self, Sample.callback)
end

def undef
ObjectSpace.undefine_finalizer(self)
end
end

Sample.new
GC.start
# => finalize

Sample.new
sample.und...
...ef
GC.start
# ※何も出力されない
//}

@see ObjectSpace.#define_finalizer...

Data.define(*args) {|subclass| block } -> Class (24374.0)

Data クラスに新しいサブクラスを作って、それを返します。

...ドが定義されています。

//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
p fred.name # => "Fred"
p fred.age # => 5
//}

メンバの値を書き換えることはできません。

//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)...
...//emlist[例][ruby]{
class HTTPFetcher
Response = Data.define(:body)
NotFound = Data.define

def get(url)
# ダミーの実装
i
f url == "http://example.com/"
Response.new(body: "Current time is #{Time.now}")
else
NotFound.new
end
end
end

def fetch(url)
fetch...
...HTTPFetcher.new
case fetcher.get(url)
i
n HTTPFetcher::Response(body)
body
i
n HTTPFetcher::NotFound
:NotFound
end
end

p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFound
//}

@param args 値オブジェ...

BasicObject#singleton_method_undefined(name) -> object (21406.0)

特異メソッドが Module#undef_method または undef により未定義にされた時にインタプリタから呼び出されます。

...特異メソッドが Module#undef_method または
u
ndef により未定義にされた時にインタプリタから呼び出されます。

通常のメソッドの未定義に対するフックには
Module#method_undefined を使います。

@param name 未定義にされたメソッド名...
.../emlist[例][ruby]{
class Foo
def singleton_method_undefined(name)
puts "singleton method \"#{name}\" was undefined"
end
end

obj = Foo.new
def obj.foo
end
def obj.bar
end

class << obj
u
ndef_method :foo
end
obj.instance_eval {undef bar}

#=> singleton method "foo" was undefined
# single...
...ton method "bar" was undefined
//}

@see Module#method_undefined,BasicObject#singleton_method_added,BasicObject#singleton_method_removed , d:spec/def#undef...

Encoding::UndefinedConversionError (21030.0)

エンコーディング変換後の文字が存在しない場合に発生する例外。

...しない場合に発生する例外。

U
TF-8 にしかない文字を EUC-JP に変換しようとした場合などに発生します。

//emlist[例][ruby]{
"\u2603".encode(Encoding::EUC_JP)
#=> Encoding::UndefinedConversionError: U+2603 from UTF-8 to EUC-JP
//}


変換が多段階でなされ...
...//emlist[例][ruby]{
ec = Encoding::Converter.new("ISO-8859-1", "EUC-JP")
# ISO-8859-1 -> UTF-8 -> EUC-JP
begin
ec.convert("\xa0")
# NO-BREAK SPACE, which is available in UTF-8 but not in EUC-JP.
rescue Encoding::UndefinedConversionError
p $!.source_encoding #=> #<Encoding:UTF-8>...
...p $!.destination_encoding #=> #<Encoding:EUC-JP>
p $!.source_encoding_name #=> "UTF-8"
p $!.destination_encoding_name #=> "EUC-JP"
puts $!.error_char.dump #=> "\u{a0}"
p $!.error_char.encoding #=> #<Encoding:UTF-8>
end
//}...

VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super) (18516.0)

super のサブクラスとして新しい Ruby クラスを、outer の定数として定義し て返します。

...super のサブクラスとして新しい Ruby クラスを、outer の定数として定義し
て返します。

@param outer 定義するクラスが定数として所属するクラス

@param name クラス名

@param super 継承元のクラス。NULL を指定した場合は Object クラ...
...

@raise TypeError 引数 name と同じ名前の定数が既に存在し、それが
Class オブジェクトではない場合に発生します。...
...

@raise TypeError 引数 name と同じ名前の定数が既に存在し、それが
Class オブジェクトではない場合に発生します。

@raise TypeError 定義済みのクラスと継承元のクラスが一致しない場合に発生
します。...

絞り込み条件を変える

Module#method_undefined(name) -> () (18306.0)

このモジュールのインスタンスメソッド name が Module#undef_method によって削除されるか、 undef 文により未定義にされると、インタプリタがこのメソッドを呼び出します。

...メソッド name が
Module#undef_method によって削除されるか、
u
ndef 文により未定義にされると、インタプリタがこのメソッドを呼び出します。

特異メソッドの削除をフックするには
BasicObject#singleton_method_undefined
を使います。

@pa...
...ド名が Symbol で渡されます。

//emlist[例][ruby]{
class C
def C.method_undefined(name)
puts "method C\##{name} was undefined"
end

def foo
end
def bar
end

u
ndef_method :foo
u
ndef bar
end
//}

実行結果:

method C#foo was undefined
method C#bar was undefined...

Module#public_method_defined?(name) -> bool (18306.0)

インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が public であるときに true を返します。 そうでなければ false を返します。

...可視性が public であるときに true を返します。
そうでなければ false を返します。

@param name Symbol か String を指定します。

@see Module#method_defined?, Module#private_method_defined?, Module#protected_method_defined?

//emlist[例][ruby]{
module A
def metho...
...protected
def method2() end
end
class C < B
i
nclude A
def method3() end
end

A.method_defined? :method1 #=> true
C.public_method_defined? "method1" #=> true
C.public_method_defined? "method2" #=> false
C.method_defined? "method2" #=> true
//}...

Module#public_method_defined?(name, inherit=true) -> bool (18306.0)

インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が public であるときに true を返します。 そうでなければ false を返します。

...ており、
しかもその可視性が public であるときに true を返します。
そうでなければ false を返します。

@param name Symbol か String を指定します。
@param inherit 真を指定するとスーパークラスや include したモジュールで
定義...
...odule#method_defined?, Module#private_method_defined?, Module#protected_method_defined?

//emlist[例][ruby]{
module A
def method1() end
end
class B
protected
def method2() end
end
class C < B
i
nclude A
def method3() end
end

A.method_defined? :method1 #=> true
C.public_...
...method_defined? "method1" #=> true
C.public_method_defined? "method1", true #=> true
C.public_method_defined? "method1", false #=> true
C.public_method_defined? "method2" #=> false
C.method_defined? "method2" #=> true
//}...

Module#const_defined?(name, inherit = true) -> bool (15406.0)

モジュールに name で指定される名前の定数が定義されている時真 を返します。

...クラスや include したモジュールで定義された定数を検索対象
にするかどうかは第二引数で制御することができます。

@param name String, Symbol で指定される定数名。

@param inherit false を指定するとスーパークラスや include したモ...
...は対象にはなりません。


//emlist[例][ruby]{
module Kernel
FOO = 1
end

# Object は include したモジュールの定数に対しても
# true を返す
p Object.const_defined?(:FOO) # => true

module Bar
BAR = 1
end
class Object
i
nclude Bar
end
# ユーザ定義のモジュ...
...同様
p Object.const_defined?(:BAR) # => true

class Baz
i
nclude Bar
end
# Object 以外でも同様になった
# 第二引数のデフォルト値が true であるため
p Baz.const_defined?(:BAR) # => true

# 第二引数を false にした場合
p Baz.const_defined?(:BAR, false) # =...

Module#method_defined?(name, inherit=true) -> bool (15406.0)

モジュールにインスタンスメソッド name が定義されており、 かつその可視性が public または protected であるときに true を返します。

...public または protected であるときに
true を返します。

@param name Symbol か String を指定します。
@param inherit 真を指定するとスーパークラスや include したモジュールで
定義されたメソッドも対象になります。

@see Module#public_...
...d_defined?, Module#private_method_defined?, Module#protected_method_defined?

//emlist[例][ruby]{
module A
def method1() end
def protected_method1() end
protected :protected_method1
end
class B
def method2() end
def private_method2() end
private :private_method2
end
class C < B
i
n...
...clude A
def method3() end
end

A.method_defined? :method1 #=> true
C.method_defined? "method1" #=> true
C.method_defined? "method2" #=> true
C.method_defined? "method2", true #=> true
C.method_defined? "method2", false #=> false
C.method_defined? "m...

絞り込み条件を変える

Module#protected_method_defined?(name, inherit=true) -> bool (15406.0)

インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が protected であるときに true を返します。 そうでなければ false を返します。

...に true を返します。
そうでなければ false を返します。

@param name Symbol か String を指定します。
@param inherit 真を指定するとスーパークラスや include したモジュールで
定義されたメソッドも対象になります。

@see Module#met...
...ined?, Module#public_method_defined?, Module#private_method_defined?

//emlist[例][ruby]{
module A
def method1() end
end
class B
protected
def method2() end
end
class C < B
i
nclude A
def method3() end
end

A.method_defined? :method1 #=> true
C.protected_method_define...
...d? "method1" #=> false
C.protected_method_defined? "method2" #=> true
C.protected_method_defined? "method2", true #=> true
C.protected_method_defined? "method2", false #=> false
C.method_defined? "method2" #=> true
//}...

TracePoint#defined_class -> Class | module (15324.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 に関係なく)モジュー
ルを返します。

//emlist[例][ruby]{
module...
...o; 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_trace_func の 6 番目の...
...スではなく元のクラスを返します。

//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 の上記の差分に注意して
ください。

@s...
<< 1 2 3 > >>