別のキーワード
種類
- インスタンスメソッド (1322)
- モジュール関数 (33)
- 特異メソッド (33)
- クラス (11)
クラス
- BasicObject (66)
- Data (18)
- Enumerator (55)
-
Enumerator
:: Lazy (11) - Fiber (26)
-
File
:: Stat (11) - Hash (83)
- IO (143)
- Method (94)
- Module (136)
- Mutex (6)
- NameError (9)
- Numeric (11)
- Object (110)
- Proc (22)
- Random (33)
- Range (23)
- String (22)
- Struct (136)
- SystemCallError (11)
- Thread (124)
-
Thread
:: Backtrace :: Location (33) -
Thread
:: ConditionVariable (18) -
Thread
:: Mutex (27) -
Thread
:: Queue (9) -
Thread
:: SizedQueue (9) - ThreadGroup (22)
- TracePoint (22)
- UnboundMethod (21)
モジュール
- Enumerable (44)
- ObjectSpace (33)
キーワード
- ! (11)
- != (11)
- < (11)
- <=> (33)
- == (35)
- === (29)
- UnboundMethod (11)
- [] (11)
-
_ dump (11) -
absolute
_ path (11) - add (11)
-
alias
_ method (8) -
backtrace
_ locations (22) -
base
_ label (11) - bind (11)
-
bind
_ call (10) - broadcast (9)
- call (22)
-
class
_ eval (22) -
class
_ exec (11) - close (18)
- coerce (11)
- deconstruct (2)
-
deconstruct
_ keys (2) - default (22)
-
define
_ finalizer (22) -
defined
_ class (11) - dig (9)
- display (11)
- each (121)
-
each
_ char (11) -
each
_ entry (22) -
each
_ line (55) -
each
_ pair (22) -
each
_ with _ index (22) - enclose (11)
- entries (6)
-
enum
_ for (22) - eql? (13)
- equal? (11)
- exit (11)
- extend (11)
- extended (11)
- hash (11)
-
initialize
_ copy (11) - inspect (46)
-
instance
_ eval (22) -
instance
_ exec (11) -
instance
_ method (11) - join (22)
- kill (11)
- merge (22)
-
module
_ eval (22) -
module
_ exec (11) - name= (9)
- owned? (11)
- private (7)
- raise (15)
- rand (33)
- receiver (9)
- reopen (22)
- replace (11)
- resume (11)
- run (11)
-
safe
_ level (5) - shift (11)
- signal (9)
-
singleton
_ methods (11) - size (11)
-
super
_ method (10) - synchronize (11)
- terminate (11)
-
to
_ a (6) -
to
_ enum (22) -
to
_ h (38) -
to
_ proc (11) -
to
_ s (46) - unbind (11)
-
undef
_ method (11) -
undefine
_ finalizer (11) - unlock (11)
- value (11)
- wakeup (11)
- with (2)
検索結果
先頭5件
-
Enumerator
:: Lazy . new(obj , size=nil) {|yielder , *values| . . . } -> Enumerator :: Lazy (21221.0) -
Lazy Enumerator を作成します。Enumerator::Lazy#force メソッドなどに よって列挙が実行されたとき、objのeachメソッドが実行され、値が一つずつ ブロックに渡されます。ブロックは、yielder を使って最終的に yield される値を 指定できます。
...Lazy Enumerator を作成します。Enumerator::Lazy#force メソッドなどに
よって列挙が実行されたとき、objのeachメソッドが実行され、値が一つずつ
ブロックに渡されます。ブロックは、yielder を使って最終的に yield される値を
指定で......st[Enumerable#filter_map と、その遅延評価版を定義する例][ruby]{
module 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)
# => [4, 16, 36, 64, 100]
//}
@raise ArgumentError 引数を指定しなかった場合、ブロックを指定しなかった場合に発生します。
@see Enumerator.new... -
Range
. new(first , last , exclude _ end = false) -> Range (18375.0) -
first から last までの範囲オブジェクトを生成して返しま す。
...first から last までの範囲オブジェクトを生成して返しま
す。
exclude_end が真ならば終端を含まない範囲オブジェクトを生
成します。exclude_end 省略時には終端を含みます。
@param first 最初のオブジェクト
@param last 最後のオブ......umentError first <=> last が nil の場合に発生します
//emlist[例: 整数の範囲オブジェクトの場合][ruby]{
Range.new(1, 10) # => 1..10
Range.new(1, 10, true) # => 1...10
//}
//emlist[例: 日付オブジェクトの範囲オブジェクトの場合][ruby]{
require 'date'......Range.new(Date.today, Date.today >> 1).each {|d| puts d }
# => 2017-09-16
# 2017-09-17
# ...
# 2017-10-16
//}
//emlist[例: IPアドレスの範囲オブジェクトの場合][ruby]{
require 'ipaddr'
Range.new(IPAddr.new("192.0.2.1"), IPAddr.new("192.0.2.3")).each {|ip| puts ip}
# => 192.0... -
Thread
# terminate -> self (9311.0) -
スレッドの実行を終了させます。終了時に ensure 節が実行されます。
...す。
ただし、スレッドは終了処理中(aborting)にはなりますが、
直ちに終了するとは限りません。すでに終了している場合は何もしません。このメソッドにより
終了したスレッドの Thread#value の返り値は不定です。
自身がメ......exit(0)
により終了します。
Kernel.#exit と違い例外 SystemExit を発生しません。
th1 = Thread.new do
begin
sleep 10
ensure
p "this will be displayed"
end
end
sleep 0.1
th1.kill
#=> "this will be displayed"
@see Kernel.#exit, Kernel.#exit!... -
Method
# super _ method -> Method | nil (9224.0) -
self 内で super を実行した際に実行されるメソッドを Method オブジェ クトにして返します。
...
self 内で super を実行した際に実行されるメソッドを Method オブジェ
クトにして返します。
@see UnboundMethod#super_method
//emlist[例][ruby]{
class Super
def foo
"superclass method"
end
end
class Sub < Super
def foo
"subclass method"
end
end
m = S......ub.new.method(:foo) # => #<Method: Sub#foo>
m.call # => "subclass method"
m.super_method # => #<Method: Super#foo>
m.super_method.call # => "superclass method"
//}... -
Thread
:: Backtrace :: Location # absolute _ path -> String (9124.0) -
self が表すフレームの絶対パスを返します。
...
self が表すフレームの絶対パスを返します。
//emlist[例][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end
Foo.new(0..2).locations.map do |call|
puts call.absolute_path
end
# => /path/to/foo.rb
# /path....../to/foo.rb
# /path/to/foo.rb
//}
@see Thread::Backtrace::Location#path... -
Module
# alias _ method(new , original) -> self (6316.0) -
メソッドの別名を定義します。
...メソッドの別名を定義します。
//emlist[例][ruby]{
module Kernel
alias_method :hoge, :puts # => Kernel
end
//}
alias との違いは以下の通りです。
* メソッド名は String または Symbol で指定します
* グローバル変数の別名をつけることはで......@param new 新しいメソッド名。String または Symbol で指定します。
@param original 元のメソッド名。String または Symbol で指定します。
@return self を返します。
@see d:spec/def#alias
//emlist[例][ruby]{
module Kernel
alias_method :foo, :puts
end
foo... -
Object
# singleton _ methods(inherited _ too = true) -> [Symbol] (6280.0) -
そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返します。
...ド名
(public あるいは protected メソッド) の一覧を返します。
inherited_too が真のときは継承した特異メソッドを含みます。
継承した特異メソッドとは Object#extend によって追加された特異メソッドや、
self がクラスの場合はスー......ton_methods(false) は、Object#methods(false) と同じです。
@param inherited_too 継承した特異メソッドを含める場合は真を、
そうでない場合は偽を指定します。
//emlist[例1][ruby]{
Parent = Class.new
class <<Parent
private; def privat......s_parent() end
protected; def protected_class_parent() end
public; def public_class_parent() end
end
Foo = Class.new(Parent)
class <<Foo
private; def private_class_foo() end
protected; def protected_class_foo() end
public; def public_class_foo() end
end
module Bar
private; d... -
Hash
# to _ h -> self | Hash (6241.0) -
self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。
...
self を返します。Hash クラスのサブクラスから呼び出した場合は
self を Hash オブジェクトに変換します。
//emlist[例][ruby]{
hash = {}
p hash.to_h # => {}
p hash.to_h == hash # => true
class MyHash < Hash;end
my_hash = MyHash.new
p my_hash.to_h # =>......{}
p my_hash.class # => MyHash
p my_hash.to_h.class # => Hash
//}......sh.class # => MyHash
p my_hash.to_h.class # => Hash
//}
ブロックを指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash = { "a" => 97, "b" => 98 }
hash.to_h {|key, value| [key.upcase, value-... -
Object
# extend(*modules) -> self (6237.0) -
引数で指定したモジュールのインスタンスメソッドを self の特異 メソッドとして追加します。
...引数で指定したモジュールのインスタンスメソッドを self の特異
メソッドとして追加します。
Module#include は、クラス(のインスタンス)に機能を追加します
が、extend は、ある特定のオブジェクトだけにモジュールの機能を......ら逆順に extend を行います。
@param modules モジュールを任意個指定します(クラスは不可)。
@return self を返します。
//emlist[][ruby]{
module Foo
def a
'ok Foo'
end
end
module Bar
def b
'ok Bar'
end
end
obj = Object.new
obj.extend Foo, Bar
p......Klass
include Foo
extend Bar
end
p Klass.new.a #=> "ok Foo"
p Klass.b #=> "ok Bar"
//}
extend の機能は、「特異クラスに対する Module#include」
と言い替えることもできます。
ただしその場合、フック用のメソッド
が Module#extended ではなく Modu... -
Object
# to _ enum(method = :each , *args) -> Enumerator (6234.0) -
Enumerator.new(self, method, *args) を返します。
...Enumerator.new(self, method, *args) を返します。
ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。
@param method メソッド名の文字列かシンボルです。
@param args 呼び出......渡される引数です。
//emlist[][ruby]{
str = "xyz"
enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]
# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}
//emlist[例(ブロックを指定する場......合)][ruby]{
module Enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size...