るりまサーチ

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

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. zlib end

検索結果

<< 1 2 3 ... > >>

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

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

...れを
配列で signature に渡してデータを定義します。例えば C における
struct
timeval {
long tv_sec;
long tv_usec;
};
という構造体型に対応して
Timeval = struct(["long tv_sec", "long tv_usec"])
として構造体に対応するクラスを生成しま...
...
返されるクラスは Fiddle::CStruct を継承しています。詳しくは
そちらを参照してください。


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

require 'fiddle/import'

module M
extend Fiddle::Importer
dlload "libc.so.6"...
...extern "int gettimeofday(void*, void*)"
Timeval = struct(["long tv_sec", "long tv_usec"])
end


time = M::Timeval.malloc
M.gettimeofday(time, Fiddle::NULL)
p time.tv_sec
p time.tv_usec...

Struct.new(*args, keyword_init: nil) -> Class (9212.0)

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

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

サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
.../emlist[例][ruby]{
Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1) # => #<struct Point1 x=1, y=nil>
Point1.new(y: 2) # => #<struct Point1 x=nil, y=2>
Point1.n...
...合は定義した Struct をコンテキストにブ
ロックを評価します。また、定義した Struct はブロックパラメータにも渡さ
れます。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address) do
def greeting
"Hello #{name}!"
end

end

Customer.new("Dave",...

Struct.new(*args, keyword_init: nil) {|subclass| block } -> Class (9212.0)

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

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

サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
.../emlist[例][ruby]{
Point1 = Struct.new(:x, :y)
Point1.new(1, 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1, y: 2) # => #<struct Point1 x=1, y=2>
Point1.new(x: 1) # => #<struct Point1 x=1, y=nil>
Point1.new(y: 2) # => #<struct Point1 x=nil, y=2>
Point1.n...
...合は定義した Struct をコンテキストにブ
ロックを評価します。また、定義した Struct はブロックパラメータにも渡さ
れます。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address) do
def greeting
"Hello #{name}!"
end

end

Customer.new("Dave",...

Struct.[](*args) -> Struct (9157.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...(このメソッドは Struct の下位クラスにのみ定義されています)
構造体オブジェクトを生成して返します。

@param args 構造体の初期値を指定します。メンバの初期値は指定されなければ nil です。

@return 構造体クラスのインス...
...タンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Struct.new(*args) -> Struct (9157.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...(このメソッドは Struct の下位クラスにのみ定義されています)
構造体オブジェクトを生成して返します。

@param args 構造体の初期値を指定します。メンバの初期値は指定されなければ nil です。

@return 構造体クラスのインス...
...タンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

絞り込み条件を変える

Struct.[](*args) -> Struct (9146.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...(このメソッドは Struct の下位クラスにのみ定義されています)
構造体オブジェクトを生成して返します。

@param args 構造体の初期値を指定します。メンバの初期値は指定されなければ nil です。

@return 構造体クラスのインス...
...タンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Struct.new(*args) -> Struct (9146.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...(このメソッドは Struct の下位クラスにのみ定義されています)
構造体オブジェクトを生成して返します。

@param args 構造体の初期値を指定します。メンバの初期値は指定されなければ nil です。

@return 構造体クラスのインス...
...タンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Struct.new(*args, keyword_init: nil) -> Class (9146.0)

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

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

サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...ださい。

//emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # Arg...
...合は定義した Struct をコンテキストにブ
ロックを評価します。また、定義した Struct はブロックパラメータにも渡さ
れます。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address) do
def greeting
"Hello #{name}!"
end

end

Customer.new("Dave",...

Struct.new(*args, keyword_init: nil) {|subclass| block } -> Class (9146.0)

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

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

サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...ださい。

//emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # Arg...
...合は定義した Struct をコンテキストにブ
ロックを評価します。また、定義した Struct はブロックパラメータにも渡さ
れます。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address) do
def greeting
"Hello #{name}!"
end

end

Customer.new("Dave",...

Struct.[](*args) -> Struct (9141.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...(このメソッドは Struct の下位クラスにのみ定義されています)
構造体オブジェクトを生成して返します。

@param args 構造体の初期値を指定します。メンバの初期値は指定されなければ nil です。

@return 構造体クラスのインス...
...タンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

絞り込み条件を変える

Struct.new(*args) -> Struct (9141.0)

(このメソッドは Struct の下位クラスにのみ定義されています) 構造体オブジェクトを生成して返します。

...(このメソッドは Struct の下位クラスにのみ定義されています)
構造体オブジェクトを生成して返します。

@param args 構造体の初期値を指定します。メンバの初期値は指定されなければ nil です。

@return 構造体クラスのインス...
...タンス。

@raise ArgumentError 構造体のメンバの数よりも多くの引数を指定した場合に発生します。

//emlist[例][ruby]{
Foo = Struct.new(:foo, :bar)
foo = Foo.new(1)
p foo.values # => [1, nil]
//}...

Struct.new(*args) -> Class (9116.0)

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

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

サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...します。

//emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # Arg...
...合は定義した Struct をコンテキストにブ
ロックを評価します。また、定義した Struct はブロックパラメータにも渡さ
れます。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address) do
def greeting
"Hello #{name}!"
end

end

Customer.new("Dave",...

Struct.new(*args) {|subclass| block } -> Class (9116.0)

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

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

サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...します。

//emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # Arg...
...合は定義した Struct をコンテキストにブ
ロックを評価します。また、定義した Struct はブロックパラメータにも渡さ
れます。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address) do
def greeting
"Hello #{name}!"
end

end

Customer.new("Dave",...

Struct.new(*args, keyword_init: false) -> Class (9116.0)

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

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

サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...します。

//emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # Arg...
...合は定義した Struct をコンテキストにブ
ロックを評価します。また、定義した Struct はブロックパラメータにも渡さ
れます。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address) do
def greeting
"Hello #{name}!"
end

end

Customer.new("Dave",...

Struct.new(*args, keyword_init: false) {|subclass| block } -> Class (9116.0)

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

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

サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "...
...します。

//emlist[例][ruby]{
Point = Struct.new(:x, :y, keyword_init: true) # => Point(keyword_init: true)
Point.new(x: 1, y: 2) # => #<struct Point x=1, y=2>
Point.new(x: 1) # => #<struct Point x=1, y=nil>
Point.new(y: 2) # => #<struct Point x=nil, y=2>
Point.new(z: 3) # Arg...
...合は定義した Struct をコンテキストにブ
ロックを評価します。また、定義した Struct はブロックパラメータにも渡さ
れます。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address) do
def greeting
"Hello #{name}!"
end

end

Customer.new("Dave",...

絞り込み条件を変える

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

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

...イルされた
RubyVM::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 RuntimeError :sc...

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

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

...day: ..7 # deconstruct_keys が使われます
puts "first Wednesday of the month"
end

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

case d
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working day in month #{month}"
end

#=> "working da...
...y in month 10" が出力される

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

//}

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

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

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

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

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

case dt
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "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_matching#matching_non_primitive_objects...

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

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

...day: ..7 # deconstruct_keys が使われます
puts "first Wednesday of the month"
end

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

case t
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working day in month #{month}"
end

#=> "working da...
...y in month 10" が出力される

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

//}

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

Data#deconstruct -> [object] (6112.0)

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

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

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

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

case distance
in n, 'km' # 裏側で #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 のサブクラス...

絞り込み条件を変える

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

self のメンバの名前と値の組を 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}
//}

このメソッドは以下のようにパターンマッチで利用さ...
...#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

//}...

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

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

..., 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, and rest columns are 2 or more" が出力される
//}

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

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

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

...: 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

#=> "first column is less than 2, and rest columns are 2 or more" が出力される
//}

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

RubyVM::InstructionSequence.of(body) -> RubyVM::InstructionSequence (3112.0)

引数 body で指定した Proc、Method オブジェクトを元に RubyVM::InstructionSequence オブジェクトを作成して返します。

...
RubyVM::InstructionSequence オブジェクトを作成して返します。

@param body Proc、Method オブジェクトを指定します。

例1:irb で実行した場合

# proc
> p = proc { num = 1 + 2 }
> RubyVM::InstructionSequence.of(p)
> # => <RubyVM::InstructionSequence:block...
...ethod
> def foo(bar); puts bar; end
> RubyVM::InstructionSequence.of(method(:foo))
> # => <RubyVM::InstructionSequence:foo@(irb)>

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

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


$a_global_proc = proc { str...
...rb
> require '/tmp/iseq_of.rb'

# hello メソッド
> RubyVM::InstructionSequence.of(method(:hello))
> # => #<RubyVM::InstructionSequence:0x007fb73d7cb1d0>

# グローバル proc
> RubyVM::InstructionSequence.of($a_global_proc)
> # => #<RubyVM::InstructionSequence:0x007fb73d7caf78>...
...irb
> require '/tmp/iseq_of.rb'

# hello メソッド
> RubyVM::InstructionSequence.of(method(:hello))
> # => #<RubyVM::InstructionSequence:0x007fb73d7cb1d0>

# グローバル proc
> RubyVM::InstructionSequence.of($a_global_proc)
> # => #<RubyVM::InstructionSequence:0x007fb73d7caf78>...

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

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

...seq = 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
> i...
...seq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
> iseq.base_label # => "<main>"

例3:

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


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

@see RubyVM::InstructionSequence#label...

絞り込み条件を変える

<< 1 2 3 ... > >>