ライブラリ
- ビルトイン (961)
クラス
- Array (24)
- Class (24)
- Data (18)
- Dir (120)
-
Enumerator
:: Lazy (12) - Fiber (28)
- File (48)
- Hash (6)
- IO (276)
- Module (36)
- Proc (14)
- Range (12)
- Regexp (24)
-
RubyVM
:: InstructionSequence (36) - Struct (48)
- Symbol (12)
- SystemCallError (12)
- Thread (96)
- TracePoint (12)
モジュール
-
RubyVM
:: AbstractSyntaxTree (10) - Warning (9)
キーワード
- === (12)
- [] (30)
-
all
_ symbols (12) - chdir (48)
- constants (12)
- current (4)
- define (6)
- delete (12)
- disasm (12)
- disassemble (12)
- each (24)
-
each
_ key (24) -
each
_ pair (24) - fork (12)
-
handle
_ interrupt (12) - kill (12)
-
last
_ match (24) - list (12)
- nesting (12)
- new (164)
- of (22)
- open (48)
- pass (12)
- path (12)
-
pending
_ interrupt? (12) - pipe (96)
- popen (168)
- rename (12)
-
ruby2
_ keywords _ hash? (6) - select (12)
- start (12)
-
try
_ convert (12) - unlink (12)
-
used
_ modules (12) - using (12)
- warn (9)
- yield (12)
検索結果
先頭5件
-
Thread
. pending _ interrupt?(error = nil) -> bool (14125.0) -
非同期割り込みのキューが空かどうかを返します。
...iate) {
Thread.pass
}
end
=== 使い方
th = Thread.new{
Thread.handle_interrupt(RuntimeError => :on_blocking){
while true
...
# ここまでで割り込みが発生しても安全な状態になった。
if Thread.pending_interrupt?
Thread.......handle_interrupt(Object => :immediate){}
end
...
end
}
}
...
th.raise # スレッド停止。
この例は以下のように記述する事もできます。
flag = true
th = Thread.new{
Thread.handle_interrupt(RuntimeError => :on_blocking){
while tru......e
...
# ここまでで割り込みが発生しても安全な状態になった。
break if flag == false
...
end
}
}
...
flag = false # スレッド停止
@see Thread#pending_interrupt?, Thread.handle_interrupt... -
Range
. new(first , last , exclude _ end = false) -> Range (8144.0) -
first から last までの範囲オブジェクトを生成して返しま す。
...て返しま
す。
exclude_end が真ならば終端を含まない範囲オブジェクトを生
成します。exclude_end 省略時には終端を含みます。
@param first 最初のオブジェクト
@param last 最後のオブジェクト
@param exclude_end 真をセットした場合終......のオブジェクトの場合][ruby]{
MyInteger = Struct.new(:value) do
def succ
self.class.new(value + 1)
end
def <=>(other)
value <=> other.value
end
def to_s
value.to_s
end
end
Range.new(MyInteger.new(1), MyInteger.new(3)).each {|i| puts i }
# => 1
# 2
# 3
//}... -
Data
. define(*args) -> Class (8055.0) -
Data クラスに新しいサブクラスを作って、それを返します。
...y: "Current time is #{Time.now}")
else
NotFound.new
end
end
end
def fetch(url)
fetcher = HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body
in HTTPFetcher::NotFound
:NotFound
end
end
p fetch("http://example.com/") # => "Current time is 2......クパラメータにも渡されます。
//emlist[例][ruby]{
Customer = Data.define(:name, :address) do
def greeting
"Hello #{name}!"
end
end
p Customer.new("Dave", "123 Main").greeting # => "Hello Dave!"
//}
なお、Dataのサブクラスのインスタンスを生成する際にオ......、
initialize メソッドをオーバーライドすることで実現できます。
//emlist[例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y: 0)
super
end
end
p Point.new(x: 1) # => #<data Point x=1, y=0>
p Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
//}... -
Data
. define(*args) {|subclass| block } -> Class (8055.0) -
Data クラスに新しいサブクラスを作って、それを返します。
...y: "Current time is #{Time.now}")
else
NotFound.new
end
end
end
def fetch(url)
fetcher = HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body
in HTTPFetcher::NotFound
:NotFound
end
end
p fetch("http://example.com/") # => "Current time is 2......クパラメータにも渡されます。
//emlist[例][ruby]{
Customer = Data.define(:name, :address) do
def greeting
"Hello #{name}!"
end
end
p Customer.new("Dave", "123 Main").greeting # => "Hello Dave!"
//}
なお、Dataのサブクラスのインスタンスを生成する際にオ......、
initialize メソッドをオーバーライドすることで実現できます。
//emlist[例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y: 0)
super
end
end
p Point.new(x: 1) # => #<data Point x=1, y=0>
p Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
//}... -
Enumerator
:: Lazy . new(obj , size=nil) {|yielder , *values| . . . } -> Enumerator :: Lazy (8031.0) -
Lazy Enumerator を作成します。Enumerator::Lazy#force メソッドなどに よって列挙が実行されたとき、objのeachメソッドが実行され、値が一つずつ ブロックに渡されます。ブロックは、yielder を使って最終的に yield される値を 指定できます。
...dule Enumerable
def filter_map(&block)
map(&block).compact
end
end
class Enumerator::Lazy
def filter_map
Lazy.new(self) do |yielder, *values|
result = yield *values
yielder << result if result
end
end
end
1.step.lazy.filter_map{|i| i*i if i.even?}.first(5)
# =>... -
TracePoint
. new(*events) {|obj| . . . } -> TracePoint (8031.0) -
新しい TracePoint オブジェクトを作成して返します。トレースを有効 にするには TracePoint#enable を実行してください。
...//emlist[例:irb で実行した場合][ruby]{
trace = TracePoint.new(:call) do |tp|
p [tp.lineno, tp.defined_class, tp.method_id, tp.event]
end
# => #<TracePoint:0x007f17372cdb20>
trace.enable
# => false
puts "Hello, TracePoint!"
# ...
# [69, IRB::Notifier::AbstractNotifier, :printf, :call]......の数指定します。
: :line
式の評価。
: :class
クラス定義、特異クラス定義、モジュール定義への突入。
: :end
クラス定義、特異クラス定義、モジュール定義の終了。
: :call
Ruby で記述されたメソッドの呼び出し。......の開始。
: :thread_end
スレッドの終了。
指定イベントに関連しない情報を取得するメソッドを実行した場合には
RuntimeError が発生します。
//emlist[例][ruby]{
TracePoint.trace(:line) do |tp|
p tp.raised_exception
end
# => RuntimeError: 'raise......の発生。
: :b_call
ブロックの開始。
: :b_return
ブロックの終了。
: :thread_begin
スレッドの開始。
: :thread_end
スレッドの終了。
: :fiber_switch
ファイバーの切り替え。
指定イベントに関連しない情報を取得するメソ......の発生。
: :b_call
ブロックの開始。
: :b_return
ブロックの終了。
: :thread_begin
スレッドの開始。
: :thread_end
スレッドの終了。
: :fiber_switch
ファイバーの切り替え。
: :script_compiled
スクリプトのコンパイル
指定... -
Data
. [](**kwargs) -> Data (8025.0) -
(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。
...現できます。
//emlist[オプション引数を実現する例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y: 0)
super
end
end
Point.new(x: 1) # => #<data Point x=1, y=0>
Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
//}
メンバに存在しない引数を......を受け取る例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y:, multiplier: 1)
super(x: x * multiplier, y: y * multiplier)
end
end
Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
Point.new(x: 1, y: 2, multiplier: 10) # => #<data Point x=10, y=20>
//}... -
Data
. [](*args) -> Data (8025.0) -
(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。
...現できます。
//emlist[オプション引数を実現する例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y: 0)
super
end
end
Point.new(x: 1) # => #<data Point x=1, y=0>
Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
//}
メンバに存在しない引数を......を受け取る例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y:, multiplier: 1)
super(x: x * multiplier, y: y * multiplier)
end
end
Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
Point.new(x: 1, y: 2, multiplier: 10) # => #<data Point x=10, y=20>
//}... -
Data
. new(**kwargs) -> Data (8025.0) -
(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。
...現できます。
//emlist[オプション引数を実現する例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y: 0)
super
end
end
Point.new(x: 1) # => #<data Point x=1, y=0>
Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
//}
メンバに存在しない引数を......を受け取る例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y:, multiplier: 1)
super(x: x * multiplier, y: y * multiplier)
end
end
Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
Point.new(x: 1, y: 2, multiplier: 10) # => #<data Point x=10, y=20>
//}... -
Data
. new(*args) -> Data (8025.0) -
(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。
...現できます。
//emlist[オプション引数を実現する例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y: 0)
super
end
end
Point.new(x: 1) # => #<data Point x=1, y=0>
Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
//}
メンバに存在しない引数を......を受け取る例][ruby]{
Point = Data.define(:x, :y) do
def initialize(x:, y:, multiplier: 1)
super(x: x * multiplier, y: y * multiplier)
end
end
Point.new(x: 1, y: 2) # => #<data Point x=1, y=2>
Point.new(x: 1, y: 2, multiplier: 10) # => #<data Point x=10, y=20>
//}... -
Module
. used _ modules -> [Module] (8025.0) -
現在のスコープで using されているすべてのモジュールを配列で返します。 配列内のモジュールの順番は未定義です。
...ープで using されているすべてのモジュールを配列で返します。
配列内のモジュールの順番は未定義です。
//emlist[例][ruby]{
module A
refine Object do
end
end
module B
refine Object do
end
end
using A
using B
p Module.used_modules
#=> [B, A]
//}... -
Dir
. new(path) -> Dir (8019.0) -
path に対するディレクトリストリームをオープンして返します。
...UTF-8>
d.close
d = Dir.new(tmpdir, encoding: Encoding::UTF_8)
p d.class # => Dir
p d.read.encoding # => #<Encoding:UTF-8>
d.close
end
//}
//emlist[例: Dir.open][ruby]{
require 'tmpdir'
Dir.mktmpdir do |tmpdir|
d = Dir.open(tmpdir, encoding: Encoding::UTF_8)
p d.class......# => Dir
p d.read.encoding # => #<Encoding:UTF-8>
d.close
Dir.open(tmpdir, encoding: Encoding::UTF_8) do |d|
p d.class # => Dir
p d.read.encoding # => #<Encoding:UTF-8>
end
end
//}... -
Dir
. new(path , encoding: Encoding . find("filesystem")) -> Dir (8019.0) -
path に対するディレクトリストリームをオープンして返します。
...UTF-8>
d.close
d = Dir.new(tmpdir, encoding: Encoding::UTF_8)
p d.class # => Dir
p d.read.encoding # => #<Encoding:UTF-8>
d.close
end
//}
//emlist[例: Dir.open][ruby]{
require 'tmpdir'
Dir.mktmpdir do |tmpdir|
d = Dir.open(tmpdir, encoding: Encoding::UTF_8)
p d.class......# => Dir
p d.read.encoding # => #<Encoding:UTF-8>
d.close
Dir.open(tmpdir, encoding: Encoding::UTF_8) do |d|
p d.class # => Dir
p d.read.encoding # => #<Encoding:UTF-8>
end
end
//}...