10件ヒット
[1-10件を表示]
(0.045秒)
ライブラリ
- ビルトイン (5)
- fiddle (1)
- psych (1)
-
rdoc
/ markup (1) -
ripper
/ filter (1) - timeout (1)
キーワード
- BasicObject (1)
- Closure (1)
- ConditionVariable (1)
- Error (1)
- Filter (1)
- Location (1)
- Markup (1)
- Method (1)
- Parser (1)
- UnboundMethod (1)
検索結果
-
Fiddle
:: Closure (166.0) -
コールバック関数を表すクラスです。
...でオブジェクトを生成することで利用します。
require 'fiddle'
include Fiddle # TYPE_* を使うために include する
class Compare < Fiddle::Closure
# qsort の比較関数は 型が int(*)(void*, void*) であるため、
# このメソッドには DL::CPtr......p s # => "()07Uabcqx"
Class.new を使うことで、サブクラスを明示的に作ることなしに
コールバックオブジェクトを作ることができます。
require 'fiddle'
include Fiddle # TYPE_* を使うために include する
compare = Class.new(Fiddle::Closure){... -
Method (166.0)
-
Object#method によりオブジェクト化され たメソッドオブジェクトのクラスです。
...、Method は大規模コードに向くと言えます。
既存のメソッドを Method オブジェクト化する。
//emlist[例][ruby]{
class Foo
def foo(arg)
"foo called with arg #{arg}"
end
end
m = Foo.new.method(:foo)
p m # => #<Method: Foo#foo>
p m.call(1) # =......cc>
p pr.call(1) # => "proc called with arg 1"
//}
Method オブジェクトが有用なのは以下のような場合。
//emlist[例][ruby]{
class Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end
obj = Foo.new
# 任意のキーとメソッドの関係をハッシュ......(Method オブジェクトはレシーバを保持する)必
要がないなら Object#public_sendを使う方法も有用。
//emlist[例][ruby]{
class Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end
# 任意のキーとメソッド(の名前)の関係をハッシュに... -
Thread
:: ConditionVariable (166.0) -
スレッドの同期機構の一つである状態変数を実現するクラスです。
...が空になった場合、
あるいは満タンになった場合に Condition Variable を使って wait しています。
require 'thread'
class TinyQueue
def initialize(max=2)
@max = max
@full = ConditionVariable.new
@empty = ConditionVariable.new
@mutex = Mut... -
UnboundMethod (112.0)
-
レシーバを持たないメソッドを表すクラスです。 呼び出すためにはレシーバにバインドする必要があります。
...とができます。
//emlist[例: Method クラスの冒頭にある例を UnboundMethod で書くと以下のようになります。][ruby]{
class Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end
# 任意のキーとメソッドの関係をハッシュに保持して......mlist[例: 以下はメソッドの再定義を UnboundMethod を使って行う方法です。普通は alias や super を使います。][ruby]{
class Foo
def foo
p :foo
end
@@orig_foo = instance_method :foo
def foo
p :bar
@@orig_foo.bind(self).call
end
end
Foo.new.foo
# =... -
Psych
:: Parser (94.0) -
YAML のパーサ。
...。
以下の例では YAML ドキュメント に含まれているスカラー値を表示します。
# Handler for detecting scalar values
class ScalarHandler < Psych::Handler
def scalar value, anchor, tag, plain, quoted, style
puts value
end
end
parser = Psych::Parser.n... -
RDoc
:: Markup (76.0) -
RDoc 形式のドキュメントを目的の形式に変換するためのクラスです。
...フォーマットを行うようにパーサを拡張する事もできます。
例:
require 'rdoc/markup'
require 'rdoc/markup/to_html'
class WikiHtml < RDoc::Markup::ToHtml
# WikiWord のフォントを赤く表示。
def handle_special_WIKIWORD(special)
"<font color=red>... -
Ripper
:: Filter (76.0) -
イベントドリブンスタイルで Ruby プログラムを加工するためのクラスです。
...e 'ripper'
require 'cgi'
class Ruby2HTML < Ripper::Filter
def on_default(event, tok, f)
f << CGI.escapeHTML(tok)
end
def on_comment(tok, f)
f << %Q[<span class="comment">#{CGI.escapeHTML(tok)}</span>]
end
def on_tstring_beg(tok, f)
f << %Q[<span class="string">#{CGI.escapeHT... -
Timeout
:: Error (76.0) -
timeout で定義される例外クラスです。 関数 timeout がタイムアウトすると発生します。
...ror のサブクラスを
定義して使用した方が無難です。
==> foo.rb <==
require 'timeout.rb'
class Foo
FooTimeoutError = Class.new(TimeoutError)
def longlongtime_method
Timeout.timeout(100, FooTimeoutError) {
...... -
Thread
:: Backtrace :: Location (58.0) -
Ruby のフレームを表すクラスです。
...例1の実行結果:
caller_locations.rb:2:in `a'
caller_locations.rb:5:in `b'
caller_locations.rb:8:in `c'
//emlist[例2][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end
Foo.new(0..2).locations.map do |call|
p... -
BasicObject (40.0)
-
特殊な用途のために意図的にほとんど何も定義されていないクラスです。 Objectクラスの親にあたります。Ruby 1.9 以降で導入されました。
...クラスから派生すべきです。
真に必要な場合にだけ BasicObject から派生してください。
=== 例
//emlist[例][ruby]{
class Proxy < BasicObject
def initialize(target)
@target = target
end
def method_missing(message, *args)
@target.__send__(message, *args...