るりまサーチ

最速Rubyリファレンスマニュアル検索!
961件ヒット [1-100件を表示] (0.265秒)

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

クラス

モジュール

オブジェクト

キーワード

検索結果

<< 1 2 3 ... > >>

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

//}...
<< 1 2 3 ... > >>