るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

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

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

...

# proc
> p = proc { num = 1 + 2 }
> RubyVM::InstructionSequence.of(p)
> # => <RubyVM::InstructionSequence:block in irb_binding@(irb)>

# method
> def foo(bar); puts bar; end
> RubyVM::InstructionSequence.of(method(:foo))
> # => <RubyVM::InstructionSequence:foo@(irb)>

例2: Ruby...
...o, world"
end


$a_global_proc = proc { str = 'a' + 'b' }

# irb
> require '/tmp/iseq_of.rb'

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

# グローバル proc
> RubyVM::InstructionSequence.of($a_glob...

RubyVM::AbstractSyntaxTree.of(proc) -> RubyVM::AbstractSyntaxTree::Node (18121.0)

引数 proc に渡したProcやメソッドオブジェクトの抽象構文木を返します。

...byVM::AbstractSyntaxTree.of(proc {1 + 2})
# => (SCOPE@2:38-2:45
# tbl: []
# args: nil
# body:
# (OPCALL@2:39-2:44 (LIT@2:39-2:40 1) :+
# (LIST@2:43-2:44 (LIT@2:43-2:44 2) nil)))

def hello
puts "hello, world"
end


pp RubyVM::AbstractSyntaxTree.of(method(:hello))
# => (SC...

RubyVM::AbstractSyntaxTree.of(proc, keep_script_lines: false, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node (18121.0)

引数 proc に渡したProcやメソッドオブジェクトの抽象構文木を返します。

...byVM::AbstractSyntaxTree.of(proc {1 + 2})
# => (SCOPE@2:38-2:45
# tbl: []
# args: nil
# body:
# (OPCALL@2:39-2:44 (LIT@2:39-2:40 1) :+
# (LIST@2:43-2:44 (LIT@2:43-2:44 2) nil)))

def hello
puts "hello, world"
end


pp RubyVM::AbstractSyntaxTree.of(method(:hello))
# => (SC...

RubyVM::AbstractSyntaxTree.of(proc) -> RubyVM::AbstractSyntaxTree::Node (18120.0)

引数 proc に渡したProcやメソッドオブジェクトの抽象構文木を返します。

...byVM::AbstractSyntaxTree.of(proc {1 + 2})
# => (SCOPE@2:38-2:45
# tbl: []
# args: nil
# body:
# (OPCALL@2:39-2:44 (LIT@2:39-2:40 1) :+
# (LIST@2:43-2:44 (LIT@2:43-2:44 2) nil)))

def hello
puts "hello, world"
end


pp RubyVM::AbstractSyntaxTree.of(method(:hello))
# => (SC...

Data.[](**kwargs) -> Data (31.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...:y)

Point.new(1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new...
...現できます。

//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 (31.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...:y)

Point.new(1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new...
...現できます。

//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 (31.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...:y)

Point.new(1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new...
...現できます。

//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 (31.0)

(このメソッドは Data のサブクラスにのみ定義されています) 値オブジェクトを生成して返します。

...:y)

Point.new(1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
Point.new...
...現できます。

//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>
//}...

Object.yaml_tag(tag) -> () (19.0)

クラスと tag の間を関連付けます。

...nitialize(x)
@x = x
end


attr_reader :x
end


# Dumps Ruby object normally
p Psych.dump(Foo.new(3))
# =>
# --- !ruby/object:Foo
# x: 3

# Registers tag with class Foo
F
oo.yaml_as("tag:example.com,2013:foo")
# ... and dumps the object of Foo class
Psych.dump(...

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

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

...rning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).

# keyword_init: falseを指定すると警告は出ない
Point2 = Struct.new(:x, :y, keyword_init: false)
Point2.new(x: 1, y: 2) # =...
...クパラメータにも渡さ
れます。

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

end

Customer.new("Dave", "123 Main").greeting # => "Hello Dave!"
//}

Structをカスタマイズする場合はこの方法が推奨されます。...
...y: 2, z: 3) # => ArgumentError (unknown keywords: z)

Point3 = Struct.new(:x, :y, keyword_init: true)
Point3.new(1, 2) # => wrong number of arguments (given 2, expected 0) (ArgumentError)
Point3.new(x: 1, y: 2) # => #<struct Point3 x=1, y=2>
Point3.new(x: 1) # => #<str...

絞り込み条件を変える

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

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

...rning: Passing only keyword arguments to Struct#initialize will behave differently from Ruby 3.2. Please use a Hash literal like .new({k: v}) instead of .new(k: v).

# keyword_init: falseを指定すると警告は出ない
Point2 = Struct.new(:x, :y, keyword_init: false)
Point2.new(x: 1, y: 2) # =...
...クパラメータにも渡さ
れます。

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

end

Customer.new("Dave", "123 Main").greeting # => "Hello Dave!"
//}

Structをカスタマイズする場合はこの方法が推奨されます。...
...y: 2, z: 3) # => ArgumentError (unknown keywords: z)

Point3 = Struct.new(:x, :y, keyword_init: true)
Point3.new(1, 2) # => wrong number of arguments (given 2, expected 0) (ArgumentError)
Point3.new(x: 1, y: 2) # => #<struct Point3 x=1, y=2>
Point3.new(x: 1) # => #<str...

Thread.handle_interrupt(hash) { ... } -> object (19.0)

スレッドの割り込みのタイミングを引数で指定した内容に変更してブロックを 実行します。

...ead.handle_interrupt(RuntimeError => :immediate) {
# ...
}
ensure
# 安全にリソースの解放が可能
end

}
end

Thread.pass
# ...
th.raise "stop"

RuntimeError を無視(延期)している間はリソースの割り当てや ensure
節でリ...
...れているため、Thread.handle_interrupt による制御が有効です。

==== Stack control settings

It's possible to stack multiple levels of ::handle_interrupt blocks in order
to control more than one ExceptionClass and TimingSymbol at a time.

Thread.handle_interrupt(FooError => :never...
...指定した例外クラスの全てのサブクラスが
処理の対象になります。

例:

Thread.handle_interrupt(Exception => :never) {
# Exception を継承する全ての例外クラスの例外の発生を延期。
}

@see Thread.pending_interrupt?, Thread#pending_interrupt?...

CSV.new(data, options = Hash.new) -> CSV (13.0)

このメソッドは CSV ファイルを読み込んだり、書き出したりするために String か IO のインスタンスをラップします。

...までを読みます。
A sequence will be selected even if it occurs in a quoted field, assuming that you
would have the same line endings there. If none of those sequences is
found, +data+ is ARGF, Object::STDIN, Object::STDOUT, or
Object::STDERR, or the stream is only available for out...
...manually if speed is important. Also
note that IO objects should be opened in binary mode on Windows if this
feature will be used as the line-ending translation can cause
problems with resetting the document position to where it was before the
read ahead. This String will be transcoded...
...st line ending beyond this
size.) If a quote cannot be found within the limit CSV will raise a
MalformedCSVError, assuming the data is faulty. You can use this limit to
prevent what are effectively DoS attacks on the parser. However, this
limit can cause a legitimate parse to fail and...

Rake::PackageTask.new(name = nil, version = nil) {|t| ... } -> Rake::PackageTask (13.0)

自身を初期化してタスクを定義します。

...task.package_dir = "./pkg"
package_task.package_files.include("lib/**/*")
end


# rake -T を実行すると以下になる
# => rake clobber_package # Remove package products
# rake package # Build all the packages
# rake repackage # Force a rebuild of the package files
//}...

SystemCallError.===(other) -> bool (13.0)

other が SystemCallError のサブクラスのインスタンスで、 かつ、other.errno の値が self::Errno と同じ場合に真を返します。そうでない場合は偽を返します。

...o の値が self::Errno と同じ場合に真を返します。そうでない場合は偽を返します。

従って、特に other が self.kind_of?(other) である場合には Module#=== と同様に真を返します。
その他に、 Errno::EXXX::Errno == Errno::EYYY::Errno である場合...
...しかありません。

@param other 任意のオブジェクト


p Errno::EAGAIN::Errno
p Errno::EWOULDBLOCK::Errno
begin
raise Errno::EAGAIN, "pseudo error"
rescue Errno::EWOULDBLOCK
p $!
end


# => 11
11
#<Errno::EAGAIN: pseudo error>...

絞り込み条件を変える

Time.httpdate(date) -> Time (13.0)

2616で定義されているHTTP-dateとしてdateをパースして Timeオブジェクトに変換します。

...2008 12:34:56 GMT'

t = Time.httpdate(rfc2616_time)
p t.kind_of?(Time) #=> true

non_rfc2616_time = 'San, 31 Aug 2008 12:34:56 GMT'
begin
Time.httpdate(non_rfc2616_time)
rescue ArgumentError => err
puts err #=> not RFC 2616 compliant date: "San, 31 Aug 2008 12:34:56 GMT"
end
...

Time.iso8601(date) -> Time (13.0)

XML Schema で定義されている dateTime として date をパースして Time オブジェクトに変換します。

...1_time)
p t #=> 2008-08-31 12:34:56 +0900
p t.kind_of?(Time) #=> true

begin
non_iso8601_time = '2008-08-31A12:34:56+09:00'
Time.iso8601(non_iso8601_time)
rescue ArgumentError => err
puts err #=> invalid date: "2008-08-31A12:34:56+09:00"
end


@see Time#xmlschema, Time#iso8601...
<< 1 2 > >>