るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Fiddle::Importer#struct(signature) -> Class (18142.0)

C の構造体型に対応する Ruby のクラスを構築して返します。

...C の構造体型に対応する Ruby のクラスを構築して返します。

構造体の各要素は C と似せた表記ができます。そしてそれを
配列で signature に渡してデータを定義します。例えば C における
struct
timeval {
long tv_sec;
long tv_u...
...sec;
};
という構造体型に対応して
Timeval = struct(["long tv_sec", "long tv_usec"])
として構造体に対応するクラスを生成します。

このメソッドが返すクラスには以下のメソッドが定義されています
* クラスメソッド malloc
* initiali...
...
返されるクラスは Fiddle::CStruct を継承しています。詳しくは
そちらを参照してください。


@param signature 構造体の各要素を文字列で表現したものの配列

require 'fiddle/import'

module M
extend Fiddle::Importer
dlload "libc.so.6"...

TracePoint#instruction_sequence -> RubyVM::InstructionSequence (6319.0)

script_compiledイベント発生時にコンパイルされた RubyVM::InstructionSequenceインスタンスを返します。

...ンパイルされた
Ruby
VM::InstructionSequenceインスタンスを返します。

//emlist[例][ruby]{
TracePoint.new(:script_compiled) do |tp|
p tp.instruction_sequence # => <RubyVM::InstructionSequence:block in <main>@(eval):1>
end
.enable do
eval("puts 'hello'")
end

//}

@raise RuntimeErr...

Data#deconstruct -> [object] (6125.0)

self のメンバの値を配列で返します。

...列で返します。

//emlist[例][ruby]{
Measure = Data.define(:amount, :unit)

distance = Measure.new(10, 'km')
distance.deconstruct # => [10, "km"]
//}

このメソッドは以下のようにパターンマッチで利用されます。

//emlist[例][ruby]{
Measure = Data.define(:amount, :uni...
...' # 裏側で #deconstruct を呼ぶ
puts "It is #{n} kilometers away"
else
puts "Don't know how to handle it"
end

# "It is 10 kilometers away" が表示される

# 以下のようにも書ける
case distance
in Measure(n, 'km')
puts "It is #{n} kilometers away"
# ...
end

//}

[注意] 本...

Data#deconstruct_keys(array_of_names_or_nil) -> Hash (6125.0)

self のメンバの名前と値の組を Hash で返します。

...の名前と値の組を Hash で返します。

//emlist[例][ruby]{
Measure = Data.define(:amount, :unit)

distance = Measure.new(10, 'km')
distance.deconstruct_keys(nil) # => {:amount=>10, :unit=>"km"}
distance.deconstruct_keys([:amount]) # => {:amount=>10}
//}

このメソッドは以下...
...れます。

//emlist[例][ruby]{
Measure = Data.define(:amount, :unit)
distance = Measure.new(10, 'km')

case distance
in amount:, unit: 'km' # 裏側で #deconstruct_keys を呼ぶ
puts "It is #{amount} kilometers away"
else
puts "Don't know how to handle it"
end

# "It is 10 kilometers away"...
...が表示される

# 以下のようにも書ける
case distance
in Measure(amount:, unit: 'km')
puts "It is #{amount} kilometers away"
# ...
end

//}

@param array_of_names_or_nil 返り値に含めるメンバの名前の配列を指定します。nil の場合は全てのメンバを意味し...

Date#deconstruct_keys(array_of_names_or_nil) -> Hash (6125.0)

パターンマッチに使用する名前と値の Hash を返します。

...l の場合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
d = Date.new(2022, 10, 5)

if d in wday: 3, day: ..7 # deconstruct_keys が使われます
puts "first Wednesday of the month"
end

#=> "first Wednesday of the month" が出力される

case d
in year: ...2022...
...month:
puts "working day in month #{month}"
end

#=> "working day in month 10" が出力される

# クラスのチェックと組み合わせて利用することもできます
if d in Date(wday: 3, day: ..7)
puts "first Wednesday of the month"
end

//}

@see d:spec/pattern_matching#matching_n...

絞り込み条件を変える

DateTime#deconstruct_keys(array_of_names_or_nil) -> Hash (6125.0)

パターンマッチに使用する名前と値の Hash を返します。

...場合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
dt = DateTime.new(2022, 10, 5, 13, 30)

if dt in wday: 1..5, hour: 10..18 # deconstruct_keys が使われます
puts "Working time"
end

#=> "Working time" が出力される

case dt
in year: ...2022
puts "too old...
...working day in month #{month}"
end

#=> "working day in month 10" が出力される

# クラスのチェックと組み合わせて利用することもできます
if dt in DateTime(wday: 1..5, hour: 10..18, day: ..7)
puts "Working time, first week of the month"
end

//}

@see d:spec/pattern_matc...

Time#deconstruct_keys(array_of_names_or_nil) -> Hash (6125.0)

パターンマッチに使用する名前と値の Hash を返します。

...合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
t = Time.utc(2022, 10, 5, 21, 25, 30)

if t in wday: 3, day: ..7 # deconstruct_keys が使われます
puts "first Wednesday of the month"
end

#=> "first Wednesday of the month" が出力される

case t
in year: ...2...
...month:
puts "working day in month #{month}"
end

#=> "working day in month 10" が出力される

# クラスのチェックと組み合わせて利用することもできます
if t in Time(wday: 3, day: ..7)
puts "first Wednesday of the month"
end

//}

@see d:spec/pattern_matching#matching_n...

CSV::Row#deconstruct -> [object] (6113.0)

パターンマッチに使用する行の値の配列を返します。

...を返します。

//emlist[例][ruby]{
require "csv"
row = CSV::Row.new(["header1", "header2", "header3"], [1, 2, 3])
case row
in [2.., 2.., 2..]
puts "all 2 or more"
in [...2, 2.., 2..]
puts "first column is less than 2, and rest columns are 2 or more"
end

#=> "first column is less than 2, an...

CSV::Row#deconstruct_keys(keys) -> Hash (6113.0)

パターンマッチに使用するヘッダの名前と値の Hash を返します。

...st[例][ruby]{
require "csv"

row = CSV::Row.new([:header1, :header2, :header3], [1, 2, 3])
case row
in { header1: 2.., header2: 2.., header3: 2.. }
puts "all 2 or more"
in { header1: ...2, header2: 2.., header3: 2.. }
puts "first column is less than 2, and rest columns are 2 or more"
end

#=> "f...

RubyVM::InstructionSequence#base_label -> String (6013.0)

self が表す命令シーケンスの基本ラベルを返します。

...iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
# => <RubyVM::InstructionSequence:<compiled>@<compiled>>
iseq.base_label
# => "<compiled>"

例2: RubyVM::InstructionSequence.compile_file を使用した場合

# /tmp/method.rb
def hello
puts "hello, world"
end


# irb...
...> iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
> iseq.base_label # => "<main>"

例3:

# /tmp/method2.rb
def hello
puts "hello, world"
end


Ruby
VM::InstructionSequence.of(method(:hello)).base_label
# => "hello"

@see RubyVM::InstructionSequence#label...

絞り込み条件を変える

RubyVM::InstructionSequence#label -> String (6013.0)

self が表す命令シーケンスのラベルを返します。通常、メソッド名、クラス名、 モジュール名などで構成されます。

... RubyVM::InstructionSequence.compile('num = 1 + 2')
# => <RubyVM::InstructionSequence:<compiled>@<compiled>>
iseq.label
# => "<compiled>"

例2: RubyVM::InstructionSequence.compile_file を使用した場合

# /tmp/method.rb
def hello
puts "hello, world"
end


# irb
> iseq = Ruby...
...VM::InstructionSequence.compile_file('/tmp/method.rb')
> iseq.label # => "<main>"

例3:

# /tmp/method2.rb
def hello
puts "hello, world"
end


Ruby
VM::InstructionSequence.of(method(:hello)).label
# => "hello"

@see RubyVM::InstructionSequence#base_label...

RubyVM::InstructionSequence#absolute_path -> String | nil (6007.0)

self が表す命令シーケンスの絶対パスを返します。

...= RubyVM::InstructionSequence.compile('num = 1 + 2')
# => <RubyVM::InstructionSequence:<compiled>@<compiled>>
iseq.absolute_path
# => nil

例2: RubyVM::InstructionSequence.compile_file を使用した場合

# /tmp/method.rb
def hello
puts "hello, world"
end


# irb
> iseq = Ruby...
...VM::InstructionSequence.compile_file('/tmp/method.rb')
> iseq.absolute_path # => "/tmp/method.rb"

@see RubyVM::InstructionSequence#path...

RubyVM::InstructionSequence#first_lineno -> Integer (6007.0)

self が表す命令シーケンスの 1 行目の行番号を返します。

...の 1 行目の行番号を返します。

例1:irb で実行した場合

Ruby
VM::InstructionSequence.compile('num = 1 + 2').first_lineno
# => 1

例2:

# /tmp/method.rb
require "foo-library"
def foo
p :foo
end


Ruby
VM::InstructionSequence.of(method(:foo)).first_lineno
# => 2...

RubyVM::InstructionSequence#path -> String (6007.0)

self が表す命令シーケンスの相対パスを返します。

...= RubyVM::InstructionSequence.compile('num = 1 + 2')
# => <RubyVM::InstructionSequence:<compiled>@<compiled>>
iseq.path
# => "<compiled>"

例2: RubyVM::InstructionSequence.compile_file を使用した場合

# /tmp/method.rb
def hello
puts "hello, world"
end


# irb
> iseq = Ruby...
...VM::InstructionSequence.compile_file('method.rb')
> iseq.path # => "method.rb"

@see RubyVM::InstructionSequence#absolute_path...

Array#pack(template) -> String (643.0)

配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。

...いことに注意してください。
buffer のサイズ(capacity)が足りなければ、packはメモリを確保します。

//emlist[例][ruby]{
['!'].pack('@1a', buffer: 'abc') # => "a!"
['!'].pack('@5a', buffer: 'abc') # => "abc\u0000\u0000!"
//}

@param template 自身のバイナリと...
...、整数サイズ非依存 (ネットワークプロトコルなどに適切)
//emlist{
n: big endian unsigned 16bit
N: big endian unsigned 32bit
v: little endian unsigned 16bit
V: little endian unsigned 32bit
//}

: エンディアン依存、整数サイズ依存 (C の構造体などに...
...ィアンの強制指定(バイナリ解析などに適切)
//emlist{
S>: big endian unsigned 16bit(nと同じ)
s>: big endian int16_t
s!>: big endian signed short
l<: little endian int32_t
l!<: little endian signed long
//}

=== 各テンプレート文字の説明

説明中、Array#p...

絞り込み条件を変える

<< 1 2 > >>