クラス
-
ARGF
. class (26) - Array (89)
- BasicObject (3)
- Binding (3)
- Class (1)
- Complex (45)
- Dir (7)
- Encoding (2)
-
Encoding
:: Converter (8) -
Encoding
:: InvalidByteSequenceError (2) - Enumerator (5)
-
Enumerator
:: Lazy (17) -
Enumerator
:: Yielder (3) - Exception (6)
- FalseClass (5)
- Fiber (2)
- File (5)
-
File
:: Stat (31) - Float (10)
- Hash (52)
- IO (46)
- Integer (4)
- LoadError (1)
- LocalJumpError (2)
- MatchData (10)
- Method (5)
- Module (49)
- NameError (2)
- NilClass (3)
- NoMethodError (1)
- Numeric (22)
- Object (36)
-
ObjectSpace
:: WeakMap (2) - Proc (7)
-
Process
:: Status (9) -
Process
:: Tms (4) - Random (3)
- Range (8)
- Rational (8)
- Regexp (10)
-
RubyVM
:: AbstractSyntaxTree :: Node (6) -
RubyVM
:: InstructionSequence (2) - SignalException (2)
- StopIteration (1)
- String (93)
- Struct (5)
- Symbol (18)
- SystemCallError (1)
- SystemExit (1)
- Thread (13)
-
Thread
:: Backtrace :: Location (3) -
Thread
:: Mutex (1) -
Thread
:: Queue (5) -
Thread
:: SizedQueue (5) - ThreadGroup (4)
- Time (24)
- TracePoint (13)
- TrueClass (4)
- UnboundMethod (3)
- UncaughtThrowError (1)
モジュール
- Comparable (8)
- Enumerable (62)
- GC (1)
キーワード
- != (1)
- !~ (1)
- & (2)
- * (1)
- ** (1)
- + (1)
- - (2)
- -@ (1)
-
/ (1) - < (3)
- << (5)
- <= (2)
- <=> (6)
- == (12)
- === (4)
- =~ (5)
- > (2)
- >= (2)
- >> (2)
- [] (11)
- []= (12)
- ^ (2)
-
_ dump (1) -
abort
_ on _ exception (1) - abs (1)
- abs2 (1)
-
absolute
_ path (2) - add (1)
- advise (1)
- all? (6)
- ancestors (1)
- angle (2)
- any? (6)
- append (1)
-
append
_ features (1) - arg (2)
-
ascii
_ compatible? (1) - assoc (1)
- atime (1)
- autoload (1)
-
backtrace
_ locations (1) - begin (1)
- between? (2)
- blksize (1)
- blocks (1)
- call (1)
-
callee
_ id (1) - capitalize (2)
- capitalize! (1)
- casecmp (2)
- casecmp? (2)
- casefold? (1)
- cause (1)
- ceil (1)
- children (2)
- chomp! (1)
- chop! (1)
- chown (1)
- chunk (1)
-
chunk
_ while (1) - clamp (3)
- class (1)
-
class
_ eval (2) -
class
_ exec (1) -
class
_ variable _ get (1) -
class
_ variable _ set (1) - clear (3)
- clone (3)
- codepoints (4)
- coerce (1)
- collect (4)
- collect! (2)
- compact! (2)
-
compare
_ by _ identity (1) -
compare
_ by _ identity? (1) - concat (4)
- conj (1)
- conjugate (1)
-
const
_ defined? (1) -
const
_ get (1) -
const
_ source _ location (1) - constants (1)
- coredump? (1)
- cover? (2)
- crypt (1)
- cstime (1)
- ctime (1)
- cutime (1)
- default (2)
- default= (1)
-
default
_ proc (1) -
default
_ proc= (1) -
define
_ method (2) -
defined
_ class (1) - delete (5)
- delete! (1)
-
delete
_ at (1) -
delete
_ if (4) -
delete
_ prefix (1) -
delete
_ prefix! (1) - denominator (1)
-
deprecate
_ constant (1) - deq (2)
- detect (2)
- dev (1)
-
dev
_ major (1) -
dev
_ minor (1) - directory? (1)
- disable (2)
- display (1)
- downcase (1)
- downcase! (1)
- drop (2)
-
drop
_ while (5) - dst? (1)
- dup (4)
- each (9)
-
each
_ byte (2) -
each
_ char (2) -
each
_ child (2) -
each
_ codepoint (4) -
each
_ cons (2) -
each
_ grapheme _ cluster (2) -
each
_ key (1) -
each
_ line (8) -
each
_ pair (2) -
each
_ slice (2) -
each
_ value (2) -
each
_ with _ index (2) - eager (1)
- empty? (6)
- enable (2)
- enabled? (1)
- enclose (1)
- enclosed? (1)
- encode! (2)
- end (1)
-
enum
_ for (2) - eql? (9)
- equal? (2)
- errno (1)
-
error
_ bytes (1) - eval (1)
-
eval
_ script (1) - event (1)
- exception (1)
- executable? (1)
-
executable
_ real? (1) - exit (1)
-
exit
_ value (1) - exited? (1)
- exitstatus (1)
- extend (1)
- extended (1)
-
external
_ encoding (1) - fdiv (2)
- feed (1)
- fetch (1)
- file? (1)
- fill (6)
-
filter
_ map (3) - find (2)
-
find
_ index (2) - finite? (1)
- first (1)
-
first
_ column (1) -
first
_ lineno (2) -
fixed
_ encoding? (1) -
flat
_ map (3) - flatten (1)
- flatten! (1)
- flock (1)
- floor (1)
-
force
_ encoding (1) - freeze (1)
- friday? (1)
- frozen? (1)
- ftype (1)
-
garbage
_ collect (1) - getc (1)
- getlocal (2)
- gets (6)
- gid (1)
- gmt? (1)
- gmtime (1)
-
grapheme
_ clusters (2) - grep (3)
-
grep
_ v (3) -
group
_ by (2) - grpowned? (1)
- gsub (1)
- gsub! (3)
-
has
_ key? (1) -
has
_ value? (1) - i (1)
- id2name (1)
- imag (1)
- imaginary (1)
- include (1)
- include? (3)
- included (1)
-
incomplete
_ input? (1) - index (4)
- infinite? (2)
- initialize (1)
-
initialize
_ copy (1) - inject (3)
- ino (1)
-
inplace
_ mode (1) -
inplace
_ mode= (1) - insert (2)
-
insert
_ output (1) - inspect (9)
-
instance
_ eval (2) -
instance
_ methods (1) -
instance
_ of? (1) -
instance
_ variable _ defined? (1) -
instance
_ variable _ get (1) -
instance
_ variable _ set (1) -
instance
_ variables (1) - intern (1)
-
internal
_ encoding (1) -
is
_ a? (1) - isdst (1)
-
keep
_ if (3) - key (1)
- key? (1)
- keys (1)
- kill (1)
-
kind
_ of? (1) - lambda? (1)
- last (2)
-
last
_ column (1) -
last
_ error (1) -
last
_ lineno (1) - lazy (2)
- length (2)
- lineno (1)
- lines (2)
- list (1)
- ljust (1)
-
local
_ variable _ set (1) -
local
_ variables (1) - localtime (2)
- lstat (1)
- lstrip (1)
- lstrip! (1)
- magnitude (1)
- map (5)
- map! (2)
-
marshal
_ dump (4) -
marshal
_ load (1) - match (5)
- match? (3)
-
max
_ by (4) - member? (2)
- members (1)
- merge (1)
- merge! (2)
-
method
_ id (1) - methods (1)
-
module
_ eval (2) -
module
_ exec (1) -
module
_ function (1) - modulo (1)
- monday? (1)
- mtime (1)
- name (2)
- nan? (1)
-
next
_ float (1) -
next
_ values (1) - nil? (1)
- nlink (1)
- none? (2)
- nonzero? (1)
- numerator (1)
- offset (2)
- one? (2)
- pack (2)
- partition (2)
- path (4)
-
peek
_ values (1) -
pending
_ interrupt? (1) - permutation (2)
- phase (3)
- pid (1)
- pipe? (1)
- polar (2)
- pop (3)
- pos (1)
- pos= (1)
- positive? (3)
- pow (1)
- pread (1)
- prepend (2)
-
prepend
_ features (1) - prepended (1)
-
prev
_ float (1) -
primitive
_ convert (4) - print (2)
- printf (2)
- priority= (1)
- private (1)
-
private
_ call? (1) -
private
_ class _ method (1) -
private
_ constant (1) -
private
_ instance _ methods (1) -
private
_ method _ defined? (1) -
private
_ methods (1) - product (2)
- protected (1)
-
protected
_ instance _ methods (1) -
protected
_ method _ defined? (1) -
protected
_ methods (1) - public (1)
-
public
_ class _ method (1) -
public
_ constant (1) -
public
_ instance _ method (1) -
public
_ instance _ methods (1) -
public
_ method (1) -
public
_ method _ defined? (1) -
public
_ methods (1) -
public
_ send (2) - push (3)
- putc (1)
- puts (2)
- quo (2)
- raise (1)
- rassoc (1)
- rationalize (6)
- rdev (1)
-
rdev
_ major (1) -
rdev
_ minor (1) - read (2)
-
read
_ nonblock (2) - readable? (1)
-
readable
_ real? (1) - readline (3)
- readlines (3)
- readpartial (2)
- real (1)
- real? (1)
- reason (1)
- rect (1)
- rectangular (1)
- reduce (3)
- rehash (1)
- reject (1)
- reject! (4)
-
remove
_ class _ variable (1) -
remove
_ const (1) -
remove
_ instance _ variable (1) - reopen (3)
-
repeated
_ combination (1) -
repeated
_ permutation (1) - replace (3)
- replacement (1)
- replacement= (1)
- replicate (1)
-
report
_ on _ exception (1) -
respond
_ to? (1) -
respond
_ to _ missing? (1) - result (1)
- resume (1)
-
return
_ value (1) - reverse! (2)
-
reverse
_ each (2) - rewind (1)
- rindex (3)
- round (3)
- rstrip! (1)
- sample (4)
- saturday? (1)
- scan (1)
- scrub (1)
- scrub! (1)
- seek (1)
- self (1)
-
set
_ backtrace (1) -
set
_ encoding (4) -
set
_ encoding _ by _ bom (1) -
set
_ trace _ func (1) - shift (4)
- signaled? (1)
- signm (1)
- signo (1)
-
singleton
_ methods (1) - size (3)
- size? (1)
- skip (1)
- sleep (1)
- slice (10)
- slice! (2)
-
slice
_ after (3) -
slice
_ before (3) -
slice
_ when (1) - sort! (2)
-
sort
_ by (2) -
source
_ location (2) - split (2)
- squeeze! (1)
-
start
_ with? (2) - step (10)
- stime (1)
- stop? (1)
- stopped? (1)
- stopsig (1)
- store (1)
- strftime (1)
- strip! (1)
- sub (1)
- sub! (2)
- subsec (1)
- success? (2)
- sum (1)
- sunday? (1)
-
super
_ method (2) - superclass (1)
- swapcase (1)
- swapcase! (1)
- symlink? (1)
- sysread (1)
- tap (1)
- tell (3)
- terminate (1)
- termsig (1)
- thursday? (1)
-
to
_ c (4) -
to
_ enum (2) -
to
_ f (3) -
to
_ h (2) -
to
_ hash (1) -
to
_ i (1) -
to
_ path (1) -
to
_ proc (3) -
to
_ r (2) -
to
_ s (6) -
to
_ sym (1) - tr (1)
- tr! (1)
-
tr
_ s (1) -
tr
_ s! (1) - truncate (1)
- tuesday? (1)
- type (1)
- uid (1)
- uniq! (2)
- unpack (1)
- unshift (1)
- upcase (1)
- upcase! (1)
- update (2)
- upto (1)
- utc (1)
- utc? (1)
- utime (1)
- value (2)
- value? (1)
- values (1)
-
values
_ at (4) - wakeup (1)
- wednesday? (1)
- writable? (1)
-
writable
_ real? (1) -
write
_ nonblock (1) - yield (2)
- zero? (2)
- zip (6)
- | (2)
- ~ (1)
検索結果
先頭5件
-
Float
# prev _ float -> Float (46234.0) -
浮動小数点数で表現可能な self の前の値を返します。
浮動小数点数で表現可能な self の前の値を返します。
(-Float::MAX).prev_float と (-Float::INFINITY).prev_float
は -Float::INFINITY を返します。Float::NAN.prev_float は
Float::NAN を返します。
//emlist[例][ruby]{
p 0.01.prev_float # => 0.009999999999999998
p 1.0.prev_float # => 0.9999999999999999
p 100.0.prev_float # => 99.9999999999... -
Class
# superclass -> Class | nil (45910.0) -
自身のスーパークラスを返します。
自身のスーパークラスを返します。
//emlist[例][ruby]{
File.superclass #=> IO
IO.superclass #=> Object
class Foo; end
class Bar < Foo; end
Bar.superclass #=> Foo
Object.superclass #=> BasicObject
//}
ただし BasicObject.superclass は nil を返します。
//emlist[例][ruby]{
BasicObject.supercl... -
Enumerable
# drop _ while {|element| . . . } -> Array (45910.0) -
ブロックを評価して最初に偽となった要素の手前の要素まで捨て、 残りの要素を配列として返します。
ブロックを評価して最初に偽となった要素の手前の要素まで捨て、
残りの要素を配列として返します。
ブロックを指定しなかった場合は、Enumerator を返します。
//emlist[例][ruby]{
a = [1, 2, 3, 4, 5, 0]
a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
//} -
ARGF
. class # inplace _ mode=(ext) (45628.0) -
c:ARGF#inplace時にバックアップファイルに付加する拡張子を設定します。 ピリオドも含めて指定する必要があります。
c:ARGF#inplace時にバックアップファイルに付加する拡張子を設定します。
ピリオドも含めて指定する必要があります。
バックアップを残さない場合は空文字列を指定します。
この機能は Windows では使用出来ません。
設定が有効になるのは次のファイルの処理に移った時です。
インプレースモードに入っていない場合はその時点でモードに入ります。
Ruby 起動時の -i オプションで設定することも出来ます。
@param ext インプレースモード時にバックアップファイルに付加する拡張子を
文字列で指定します。
ピリオドも含める必要があ... -
ARGF
. class # inplace _ mode -> String | nil (45610.0) -
c:ARGF#inplace で書き換えるファイルのバックアップに付加される拡 張子を返します。拡張子が設定されていない場合は空文字列を返します。イン プレースモードでない場合は nil を返します。
c:ARGF#inplace で書き換えるファイルのバックアップに付加される拡
張子を返します。拡張子が設定されていない場合は空文字列を返します。イン
プレースモードでない場合は nil を返します。
Ruby 起動時の -i オプション や ARGF.class#inplace_mode= で設定します。
例:
# $ echo "test" > test.txt
# $ ruby -i.bak test.rb test.txt
# $ cat test.txt # => "TEST"
# $ cat test.txt.bak # => "test"
# test... -
Enumerable
# drop _ while -> Enumerator (45610.0) -
ブロックを評価して最初に偽となった要素の手前の要素まで捨て、 残りの要素を配列として返します。
ブロックを評価して最初に偽となった要素の手前の要素まで捨て、
残りの要素を配列として返します。
ブロックを指定しなかった場合は、Enumerator を返します。
//emlist[例][ruby]{
a = [1, 2, 3, 4, 5, 0]
a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
//} -
String
# split(sep = $ ; , limit = 0) -> [String] (37216.0) -
第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。 ブロックを指定すると、配列を返す代わりに分割した文字列で ブロックを呼び出します。
第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、
結果を文字列の配列で返します。
ブロックを指定すると、配列を返す代わりに分割した文字列で
ブロックを呼び出します。
第 1 引数 sep は以下のいずれかです。
: 正規表現
正規表現にマッチする部分で分割する。
特に、括弧によるグルーピングがあればそのグループにマッチした
文字列も結果の配列に含まれる (後述)。
: 文字列
その文字列自体にマッチする部分で分割する。
: 1 バイトの空白文字 ' '
先頭と末尾の空白を除いたうえで、空白文字列で分割する。
... -
String
# split(sep = $ ; , limit = 0) {|s| . . . } -> self (37216.0) -
第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。 ブロックを指定すると、配列を返す代わりに分割した文字列で ブロックを呼び出します。
第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、
結果を文字列の配列で返します。
ブロックを指定すると、配列を返す代わりに分割した文字列で
ブロックを呼び出します。
第 1 引数 sep は以下のいずれかです。
: 正規表現
正規表現にマッチする部分で分割する。
特に、括弧によるグルーピングがあればそのグループにマッチした
文字列も結果の配列に含まれる (後述)。
: 文字列
その文字列自体にマッチする部分で分割する。
: 1 バイトの空白文字 ' '
先頭と末尾の空白を除いたうえで、空白文字列で分割する。
... -
String
# each _ grapheme _ cluster {|grapheme _ cluster| block } -> self (37210.0) -
文字列の書記素クラスタに対して繰り返します。
文字列の書記素クラスタに対して繰り返します。
String#each_char と違って、
Unicode Standard Annex #29 (https://unicode.org/reports/tr29/)
で定義された書記素クラスタに対して繰り返します。
//emlist[例][ruby]{
"a\u0300".each_char.to_a.size # => 2
"a\u0300".each_grapheme_cluster.to_a.size # => 1
//}
@see String#grapheme_clusters -
String
# grapheme _ clusters {|grapheme _ cluster| block } -> self (37210.0) -
文字列の書記素クラスタの配列を返します。(self.each_grapheme_cluster.to_a と同じです)
文字列の書記素クラスタの配列を返します。(self.each_grapheme_cluster.to_a と同じです)
//emlist[例][ruby]{
"a\u0300".grapheme_clusters # => ["à"]
//}
ブロックが指定された場合は String#each_grapheme_cluster と同じように動作します。
Ruby 2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。
@see String#each_grapheme_cluster -
Hash
# default _ proc=(pr) (37036.0) -
ハッシュのデフォルト値を返す Proc オブジェクトを 変更します。
ハッシュのデフォルト値を返す Proc オブジェクトを
変更します。
以前のデフォルトは値(Hash#default)の場合も
Proc の場合(Hash#default_proc)でも上書きされます。
引数には to_proc で Proc オブジェクトに変換できる
オブジェクトも受け付けます。
nil を指定した場合は現在の Hash#default_proc をクリアします。
@param pr デフォルト値を返す手続きオブジェクト
//emlist[例][ruby]{
h = {}
h.default_proc = proc do |hash, key|
hash[ke... -
Hash
# default _ proc -> Proc | nil (37000.0) -
ハッシュのデフォルト値を返す Proc オブジェクトを返します。 ハッシュがブロック形式のデフォルト値を持たない場合 nil を返します。
ハッシュのデフォルト値を返す Proc オブジェクトを返します。
ハッシュがブロック形式のデフォルト値を持たない場合 nil を返します。
//emlist[例][ruby]{
h = Hash.new {|hash, key| "The #{key} not exist in #{hash.inspect}"}
p h.default #=> nil
p block = h.default_proc #=> #<Proc:0x0x401a9ff4>
p block.call({},:foo) #=> "The foo not exist in {}"
h... -
Array
# repeated _ permutation(n) { |p| . . . } -> self (36913.0) -
サイズ n の重複順列をすべて生成し,それを引数としてブロックを実行します。
サイズ n の重複順列をすべて生成し,それを引数としてブロックを実行します。
得られる順列の順序は保証されません。ブロックなしで呼び出されると, 順列
を生成する Enumerator オブジェクトを返します。
@param n 生成する配列のサイズを整数で指定します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる暗
黙の型変換を試みます。
@raise TypeError 引数に整数以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。
//emlist[例][ruby... -
Array
# drop _ while {|element| . . . } -> Array (36910.0) -
ブロックを評価して最初に偽となった要素の手前の要素まで捨て、 残りの要素を配列として返します。 このメソッドは自身を破壊的に変更しません。
ブロックを評価して最初に偽となった要素の手前の要素まで捨て、
残りの要素を配列として返します。
このメソッドは自身を破壊的に変更しません。
ブロックを指定しなかった場合は、Enumerator を返します。
//emlist[例][ruby]{
a = [1, 2, 3, 4, 5, 0]
a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
# 変数aの値は変化しない
a # => [1, 2, 3, 4, 5, 0]
//}
@see Enumerable#drop_while, Array... -
String
# delete _ prefix!(prefix) -> self | nil (36910.0) -
self の先頭から破壊的に prefix を削除します。
self の先頭から破壊的に prefix を削除します。
@param prefix 先頭から削除する文字列を指定します。
@return 削除した場合は self、変化しなかった場合は nil
//emlist[][ruby]{
"hello".delete_prefix!("hel") # => "lo"
"hello".delete_prefix!("llo") # => nil
//}
@see String#delete_prefix
@see String#delete_suffix!
@see String#start_with? -
String
# delete _ prefix(prefix) -> String (36910.0) -
文字列の先頭から prefix を削除した文字列のコピーを返します。
文字列の先頭から prefix を削除した文字列のコピーを返します。
@param prefix 先頭から削除する文字列を指定します。
@return 文字列の先頭から prefix を削除した文字列のコピー
//emlist[][ruby]{
"hello".delete_prefix("hel") # => "lo"
"hello".delete_prefix("llo") # => "hello"
//}
@see String#delete_prefix!
@see String#delete_suffix
@see String#start_with? -
Enumerator
# peek _ values -> Array (36700.0) -
Enumerator#next_values のように「次」のオブジェクトを 配列で返しますが、列挙状態を変化させません。
Enumerator#next_values のように「次」のオブジェクトを
配列で返しますが、列挙状態を変化させません。
Enumerator#next, Enumerator#next_values のように
現在までの列挙状態に応じて「次」のオブジェクトを返しますが、
next と異なり列挙状態を変更しません。
列挙が既に最後へ到達している場合は、StopIteration 例外を発生します。
このメソッドは Enumerator#next_values と同様
yield
と
yield nil
を区別するために使えます。
//emlist[例][ruby]{
o =... -
Array
# sample -> object | nil (36682.0) -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個)
ランダムに選んで返します。
重複したインデックスは選択されません。そのため、自身がユニークな配列の
場合は返り値もユニークな配列になります。
配列が空の場合、無引数の場合は nil を、個数を指定した場合は空配列を返します。
srand()が有効です。
@param n 取得する要素の数を指定します。自身の要素数(self.length)以上の
値を指定した場合は要素数と同じ数の配列を返します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる暗
... -
Array
# sample(n) -> Array (36682.0) -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個)
ランダムに選んで返します。
重複したインデックスは選択されません。そのため、自身がユニークな配列の
場合は返り値もユニークな配列になります。
配列が空の場合、無引数の場合は nil を、個数を指定した場合は空配列を返します。
srand()が有効です。
@param n 取得する要素の数を指定します。自身の要素数(self.length)以上の
値を指定した場合は要素数と同じ数の配列を返します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる暗
... -
Array
# sample(n , random: Random) -> Array (36682.0) -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個)
ランダムに選んで返します。
重複したインデックスは選択されません。そのため、自身がユニークな配列の
場合は返り値もユニークな配列になります。
配列が空の場合、無引数の場合は nil を、個数を指定した場合は空配列を返します。
srand()が有効です。
@param n 取得する要素の数を指定します。自身の要素数(self.length)以上の
値を指定した場合は要素数と同じ数の配列を返します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる暗
... -
Array
# sample(random: Random) -> object | nil (36682.0) -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個)
ランダムに選んで返します。
重複したインデックスは選択されません。そのため、自身がユニークな配列の
場合は返り値もユニークな配列になります。
配列が空の場合、無引数の場合は nil を、個数を指定した場合は空配列を返します。
srand()が有効です。
@param n 取得する要素の数を指定します。自身の要素数(self.length)以上の
値を指定した場合は要素数と同じ数の配列を返します。
整数以外のオブジェクトを指定した場合は to_int メソッドによる暗
... -
Encoding
:: InvalidByteSequenceError # incomplete _ input? -> bool (36682.0) -
エラー発生時に入力文字列が不足している場合に真を返します。
エラー発生時に入力文字列が不足している場合に真を返します。
つまり、マルチバイト文字列の途中で文字列が終わっている場合に
真を返します。これは後続の入力を追加することでエラーが
解消する可能性があることを意味します。
//emlist[例][ruby]{
ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
begin
ec.convert("abc\xA1z")
rescue Encoding::InvalidByteSequenceError
p $!
#=> #<Encoding::InvalidByteSequenc... -
Module
# public(*name) -> self (36682.0) -
メソッドを public に設定します。
メソッドを public に設定します。
引数なしのときは今後このクラスまたはモジュール定義内で新規に定義さ
れるメソッドをどんな形式でも呼び出せるように(public)設定します。
引数が与えられた時には引数によって指定されたメソッドを public に設
定します。
可視性については d:spec/def#limit を参照して下さい。
@param name 0 個以上の String または Symbol を指定します。
@raise NameError 存在しないメソッド名を指定した場合に発生します。
//emlist[例][ruby]{
def foo() 1 en... -
Object
# marshal _ dump -> object (36682.0) -
Marshal.#dump を制御するメソッドです。
Marshal.#dump を制御するメソッドです。
Marshal.dump(some) において、出力するオブジェクト some がメソッド marshal_dump を
持つ場合には、その返り値がダンプされたものが Marshal.dump(some) の返り値となります。
marshal_dump/marshal_load の仕組みは Ruby 1.8.0 から導入されました。
これから書くプログラムでは _dump/_load ではなく
marshal_dump/marshal_load を使うべきです。
@return 任意のオブジェクトで marshal_load の引数... -
String
# lstrip! -> self | nil (36682.0) -
文字列の先頭にある空白文字を全て破壊的に取り除きます。 空白文字の定義は " \t\r\n\f\v" です。
文字列の先頭にある空白文字を全て破壊的に取り除きます。
空白文字の定義は " \t\r\n\f\v" です。
lstrip! は self を変更して返します。
ただし取り除く空白がなかったときは nil を返します。
//emlist[例][ruby]{
str = " abc"
p str.lstrip! # => "abc"
p str # => "abc"
str = "abc"
p str.lstrip! # => nil
p str # => "abc"
//} -
Hash
# replace(other) -> self (36664.0) -
ハッシュの内容を other の内容で置き換えます。
ハッシュの内容を other の内容で置き換えます。
デフォルト値の設定もotherの内容になります。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。
self = other.to_hash.dup と同じです。
@param other ハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return self を返します。
//emlist[例][ruby]{
foo = {1 => 'a', 2 => 'b'}
bar = {2 => 'B', 3 => 'C'}
foo.replace(b... -
Random
# marshal _ dump -> Array (36664.0) -
Random#marshal_load で復元可能な配列を返します。
Random#marshal_load で復元可能な配列を返します。
//emlist[例][ruby]{
r1 = Random.new(1)
a1 = r1.marshal_dump
r2 = Random.new(3)
p r1 == r2 # => false
r3 = r2.marshal_load(a1)
p r1 == r2 # => true
p r1 == r3 # => true
//} -
String
# capitalize(*options) -> String (36664.0) -
文字列先頭の文字を大文字に、残りを小文字に変更した文字列を返します。
文字列先頭の文字を大文字に、残りを小文字に変更した文字列を返します。
@param options オプションの詳細は String#downcase を参照してください。
//emlist[例][ruby]{
p "foobar--".capitalize # => "Foobar--"
p "fooBAR--".capitalize # => "Foobar--"
p "FOOBAR--".capitalize # => "Foobar--"
//}
@see String#capitalize!, String#upcase,
String#downcase... -
String
# lstrip -> String (36664.0) -
文字列の先頭にある空白文字を全て取り除いた新しい文字列を返します。 空白文字の定義は " \t\r\n\f\v" です。
文字列の先頭にある空白文字を全て取り除いた新しい文字列を返します。
空白文字の定義は " \t\r\n\f\v" です。
//emlist[例][ruby]{
p " abc\n".lstrip #=> "abc\n"
p "\t abc\n".lstrip #=> "abc\n"
p "abc\n".lstrip #=> "abc\n"
//}
@see String#strip, String#rstrip -
Encoding
:: Converter # replacement -> String (36646.0) -
変換器に設定されている置換文字を返します。
変換器に設定されている置換文字を返します。
@return 変換器に設定されている置換文字
//emlist[][ruby]{
ec = Encoding::Converter.new("euc-jp", "us-ascii")
p ec.replacement #=> "?"
ec = Encoding::Converter.new("euc-jp", "utf-8")
p ec.replacement #=> "\uFFFD"
//} -
Module
# public _ instance _ method(name) -> UnboundMethod (36646.0) -
self の public インスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
self の public インスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
@param name メソッド名を Symbol または String で指定します。
@raise NameError 定義されていないメソッド名や、
protected メソッド名、 private メソッド名を引数として与えると発生します。
//emlist[例][ruby]{
Kernel.public_instance_method(:object_id) #=> #<UnboundMethod: Kernel#object_id>
Ke... -
Object
# initialize _ copy(obj) -> object (36646.0) -
(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。
(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。
このメソッドは self を obj の内容で置き換えます。ただ
し、self のインスタンス変数や特異メソッドは変化しません。
Object#clone, Object#dupの内部で使われています。
initialize_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに使用(定義)されます。例えば C 言語でクラスを実装する場合、情報
をインスタンス変数に保持させない場合がありますが、そういった内部情
報を initialize_copy でコピーするよう定義しておくことで、du... -
Object
# public _ method(name) -> Method (36646.0) -
オブジェクトの public メソッド name をオブジェクト化した Method オブジェクトを返します。
オブジェクトの public メソッド name をオブジェクト化した
Method オブジェクトを返します。
@param name メソッド名を Symbol または String で指定します。
@raise NameError 定義されていないメソッド名や、
protected メソッド名、 private メソッド名を引数として与えると発生します。
//emlist[][ruby]{
1.public_method(:to_int) #=> #<Method: Integer#to_int>
1.public_method(:p) # method ... -
String
# capitalize!(*options) -> self | nil (36646.0) -
文字列先頭の文字を大文字に、残りを小文字に破壊的に変更します。
文字列先頭の文字を大文字に、残りを小文字に破壊的に変更します。
@param options オプションの詳細は String#downcase を参照してください。
@return capitalize! は self を変更して返しますが、
変更が起こらなかった場合は nil を返します。
//emlist[例][ruby]{
str = "foobar"
str.capitalize!
p str # => "Foobar"
str = "fooBAR"
str.capitalize!
p str # => "Foobar"
//}
@see Stri... -
Array
# replace(another) -> self (36628.0) -
配列の内容を配列 another の内容で置き換えます。
配列の内容を配列 another の内容で置き換えます。
@param another 配列を指定します。
配列以外のオブジェクトを指定した場合は to_ary メソッドに
よる暗黙の型変換を試みます。
@raise TypeError 引数に配列以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。
//emlist[例][ruby]{
a = [1, 2, 3]
a.replace [4, 5, 6]
p a #=> [4, 5, 6]
... -
Encoding
:: Converter # replacement=(string) (36628.0) -
置換文字を設定します。
置換文字を設定します。
@param string 変換器に設定する置換文字
//emlist[][ruby]{
ec = Encoding::Converter.new("utf-8", "us-ascii", :undef => :replace)
ec.replacement = "<undef>"
p ec.convert("a \u3042 b") #=> "a <undef> b"
//} -
String
# replace(other) -> String (36628.0) -
self の内容を other の内容で置き換えます。
self の内容を other の内容で置き換えます。
//emlist[例][ruby]{
str = "foo"
str.replace "bar"
p str # => "bar"
//} -
TracePoint
# eval _ script -> String | nil (36628.0) -
script_compiledイベント発生時にコンパイルされたソースコードを返します。 ファイルから読み込んだ場合は、nilを返します。
script_compiledイベント発生時にコンパイルされたソースコードを返します。
ファイルから読み込んだ場合は、nilを返します。
//emlist[例][ruby]{
TracePoint.new(:script_compiled) do |tp|
p tp.eval_script # => "puts 'hello'"
end.enable do
eval("puts 'hello'")
end
//}
@raise RuntimeError :script_compiled イベントのための
イベントフックの外側で実行した場合に... -
ARGF
. class # readpartial(maxlen , outbuf = nil) -> String (36610.0) -
IO#readpartialを参照。ARGF.class#read などとは違って複数ファ イルを同時に読み込むことはありません。
IO#readpartialを参照。ARGF.class#read などとは違って複数ファ
イルを同時に読み込むことはありません。
@param maxlen 読み込む長さの上限を整数で指定します。
@param outbuf 読み込んだデータを格納する String オブジェクトを指定します。
@see IO#readpartial, ARGF.class#read_nonblock -
Array
# drop _ while -> Enumerator (36610.0) -
ブロックを評価して最初に偽となった要素の手前の要素まで捨て、 残りの要素を配列として返します。 このメソッドは自身を破壊的に変更しません。
ブロックを評価して最初に偽となった要素の手前の要素まで捨て、
残りの要素を配列として返します。
このメソッドは自身を破壊的に変更しません。
ブロックを指定しなかった場合は、Enumerator を返します。
//emlist[例][ruby]{
a = [1, 2, 3, 4, 5, 0]
a.drop_while {|i| i < 3 } # => [3, 4, 5, 0]
# 変数aの値は変化しない
a # => [1, 2, 3, 4, 5, 0]
//}
@see Enumerable#drop_while, Array... -
Comparable
# clamp(min , max) -> object (36610.0) -
self を範囲内に収めます。
self を範囲内に収めます。
min と max の2つの引数が渡された場合は次のようになります。
self <=> min が負数を返したときは min を、
self <=> max が正数を返したときは max を、
それ以外の場合は self を返します。
range が1つ渡された場合は次のようになります。
self <=> range.begin が負数を返したときは range.begin を、
self <=> range.end が正数を返したときは range.end を、
それ以外の場合は self を返します。
range.begin が nil の場合、r... -
Comparable
# clamp(range) -> object (36610.0) -
self を範囲内に収めます。
self を範囲内に収めます。
min と max の2つの引数が渡された場合は次のようになります。
self <=> min が負数を返したときは min を、
self <=> max が正数を返したときは max を、
それ以外の場合は self を返します。
range が1つ渡された場合は次のようになります。
self <=> range.begin が負数を返したときは range.begin を、
self <=> range.end が正数を返したときは range.end を、
それ以外の場合は self を返します。
range.begin が nil の場合、r... -
Complex
# clamp(range) -> object (36610.0) -
@undef
@undef -
Complex
# marshal _ dump -> Array (36610.0) -
Marshal.#load のためのメソッドです。 Complex::compatible#marshal_load で復元可能な配列を返します。
Marshal.#load のためのメソッドです。
Complex::compatible#marshal_load で復元可能な配列を返します。
2.0 以降では Marshal.#load で 1.8 系の Complex オブジェクト
を保存した文字列も復元できます。
[注意] Complex::compatible は通常の方法では参照する事ができません。 -
Complex
# phase -> Float (36610.0) -
自身の偏角を[-π,π]の範囲で返します。
自身の偏角を[-π,π]の範囲で返します。
//emlist[例][ruby]{
Complex.polar(3, Math::PI/2).arg # => 1.5707963267948966
//}
非正の実軸付近での挙動に注意してください。以下の例のように虚部が 0.0 と
-0.0 では値が変わります。
//emlist[例][ruby]{
Complex(-1, 0).arg #=> 3.141592653589793
Complex(-1, -0).arg #=> 3.141592653589793
Complex(-1... -
Complex
# polar -> [Numeric , Numeric] (36610.0) -
自身の絶対値と偏角を配列にして返します。
自身の絶対値と偏角を配列にして返します。
//emlist[例][ruby]{
Complex.polar(1, 2).polar # => [1, 2]
//}
@see Numeric#polar -
Encoding
# ascii _ compatible? -> bool (36610.0) -
自身が ASCII 互換のエンコーディングである場合真返します。 そうでない場合は偽を返します。
自身が ASCII 互換のエンコーディングである場合真返します。
そうでない場合は偽を返します。
//emlist[例][ruby]{
Encoding::UTF_8.ascii_compatible? #=> true
Encoding::UTF_16BE.ascii_compatible? #=> false
//} -
Encoding
# replicate(name) -> Encoding (36610.0) -
レシーバのエンコーディングを複製(replicate)します。 複製されたエンコーディングは元のエンコーディングと同じバイト構造を持たなければなりません。 name という名前のエンコーディングが既に存在する場合は ArgumentError を発生します。
レシーバのエンコーディングを複製(replicate)します。
複製されたエンコーディングは元のエンコーディングと同じバイト構造を持たなければなりません。
name という名前のエンコーディングが既に存在する場合は ArgumentError を発生します。
Ruby 3.2 から非推奨となり、Ruby 3.3 で削除予定です。
//emlist[][ruby]{
encoding = Encoding::UTF_8.replicate("REPLICATED_UTF-8") #=> #<Encoding:REPLICATED_UTF-8>
encoding.name ... -
Enumerable
# filter _ map -> Enumerator (36610.0) -
各要素に対してブロックを評価した値のうち、真であった値の 配列を返します。
各要素に対してブロックを評価した値のうち、真であった値の
配列を返します。
ブロックを省略した場合は Enumerator を返します。
//emlist[例][ruby]{
(1..10).filter_map { |i| i * 2 if i.even? } #=> [4, 8, 12, 16, 20]
//}
@see Enumerable#filter, Enumerable#map -
Enumerable
# filter _ map {|item| . . . } -> [object] (36610.0) -
各要素に対してブロックを評価した値のうち、真であった値の 配列を返します。
各要素に対してブロックを評価した値のうち、真であった値の
配列を返します。
ブロックを省略した場合は Enumerator を返します。
//emlist[例][ruby]{
(1..10).filter_map { |i| i * 2 if i.even? } #=> [4, 8, 12, 16, 20]
//}
@see Enumerable#filter, Enumerable#map -
Enumerable
# flat _ map -> Enumerator (36610.0) -
各要素をブロックに渡し、その返り値を連結した配列を返します。
各要素をブロックに渡し、その返り値を連結した配列を返します。
ブロックの返り値は基本的に配列を返すべきです。
ブロックを省略した場合は Enumerator を返します。
//emlist[例][ruby]{
[[1,2], [3,4]].flat_map{|i| i.map{|j| j*2}} # => [2,4,6,8]
//} -
Enumerable
# flat _ map {| obj | block } -> Array (36610.0) -
各要素をブロックに渡し、その返り値を連結した配列を返します。
各要素をブロックに渡し、その返り値を連結した配列を返します。
ブロックの返り値は基本的に配列を返すべきです。
ブロックを省略した場合は Enumerator を返します。
//emlist[例][ruby]{
[[1,2], [3,4]].flat_map{|i| i.map{|j| j*2}} # => [2,4,6,8]
//} -
Enumerator
:: Lazy # drop _ while {|item| . . . } -> Enumerator :: Lazy (36610.0) -
Enumerable#drop_while と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#drop_while と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.drop_while { |i| i < 42 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:drop_while>
1.step.lazy.drop_while { |i| i < 42 }.take(10).force
# => [42, 43, 44, 45, 46, 47, 48, 49, 50, 51]
//... -
Enumerator
:: Lazy # filter _ map {|item| . . . } -> Enumerator :: Lazy (36610.0) -
Enumerable#filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。
Enumerable#filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。
@raise ArgumentError ブロックを指定しなかった場合に発生します。
//emlist[例][ruby]{
1.step.lazy.filter_map { |n| n * 2 if n.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: (1.step)>:filter_map>
1.step.lazy.filter_map { |n| n * 2 if n.even? }.take(10).fo... -
IO
# readpartial(maxlen , outbuf = "") -> String (36610.0) -
IO から長さ maxlen を上限として読み込み、文字列として返します。 即座に得られるデータが存在しないときにはブロックしてデータの到着を待ちます。 即座に得られるデータが 1byte でも存在すればブロックしません。
IO から長さ maxlen を上限として読み込み、文字列として返します。
即座に得られるデータが存在しないときにはブロックしてデータの到着を待ちます。
即座に得られるデータが 1byte でも存在すればブロックしません。
バイナリ読み込みメソッドとして動作します。
既に EOF に達していれば EOFError が発生します。
ただし、maxlen に 0 が指定されている場合は、空文字列 "" を返します。
readpartial はブロックを最小限に抑えることによって、
パイプ、ソケット、端末などのストリームに対して適切に動作するよう設計されています。
readpartial が... -
Module
# private _ class _ method(*name) -> self (36610.0) -
name で指定したクラスメソッド (クラスの特異メソッド) の 可視性を private に変更します。
name で指定したクラスメソッド (クラスの特異メソッド) の
可視性を private に変更します。
@param name 0 個以上の String または Symbol を指定します。
//emlist[例][ruby]{
module Foo
def self.foo; end
end
Foo.singleton_class.private_method_defined?(:foo) # => false
Foo.private_class_method(:foo) # => Foo
Foo.singleton_class.private_method_define... -
Module
# public _ class _ method(*name) -> self (36610.0) -
name で指定したクラスメソッド (クラスの特異メソッド) の 可視性を public に変更します。
name で指定したクラスメソッド (クラスの特異メソッド) の
可視性を public に変更します。
@param name 0 個以上の String または Symbol を指定します。
//emlist[例][ruby]{
class Foo
def self.foo
"foo"
end
private_class_method :foo
end
Foo.foo # NoMethodError: private method `foo' called for Foo:Class
Foo.public_class_method(:foo) # => F... -
Module
# public _ constant(*name) -> self (36610.0) -
name で指定した定数の可視性を public に変更します。
name で指定した定数の可視性を public に変更します。
@param name 0 個以上の String か Symbol を指定します。
@raise NameError 存在しない定数を指定した場合に発生します。
@return self を返します。
//emlist[例][ruby]{
module SampleModule
class SampleInnerClass
end
# => 非公開クラスであることを明示するために private にする
private_constant :SampleInnerClass
end
begin
... -
Module
# public _ instance _ methods(inherited _ too = true) -> [Symbol] (36610.0) -
そのモジュールで定義されている public メソッド名 の一覧を配列で返します。
そのモジュールで定義されている public メソッド名
の一覧を配列で返します。
@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。
@see Object#public_methods, Module#instance_methods -
Module
# public _ method _ defined?(name , inherit=true) -> bool (36610.0) -
インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が public であるときに true を返します。 そうでなければ false を返します。
インスタンスメソッド name がモジュールに定義されており、
しかもその可視性が public であるときに true を返します。
そうでなければ false を返します。
@param name Symbol か String を指定します。
@param inherit 真を指定するとスーパークラスや include したモジュールで
定義されたメソッドも対象になります。
@see Module#method_defined?, Module#private_method_defined?, Module#protected_method_defined?
//e... -
NoMethodError
# private _ call? -> bool (36610.0) -
メソッド呼び出しが private なメソッドを呼び出せる形式 (関数形式(レシーバを省略した形式)) で呼ばれたかどうかを返します。
メソッド呼び出しが private なメソッドを呼び出せる形式
(関数形式(レシーバを省略した形式)) で呼ばれたかどうかを返します。 -
Numeric
# polar -> [Numeric , Numeric] (36610.0) -
自身の絶対値と偏角を配列にして返します。正の数なら [self, 0]、負の数な ら [-self, Math::PI] を返します。
自身の絶対値と偏角を配列にして返します。正の数なら [self, 0]、負の数な
ら [-self, Math::PI] を返します。
//emlist[例][ruby]{
1.0.polar # => [1.0, 0]
2.0.polar # => [2.0, 0]
-1.0.polar # => [1.0, 3.141592653589793]
-2.0.polar # => [2.0, 3.141592653589793]
//}
Numeric のサブクラスは、このメソッドを適切に再定義しなければなりません。
@see Complex#polar -
Object
# display(out = $ stdout) -> nil (36610.0) -
オブジェクトを out に出力します。
オブジェクトを out に出力します。
以下のように定義されています。
//emlist[][ruby]{
class Object
def display(out = $stdout)
out.write self
nil
end
end
//}
@param out 出力先のIOオブジェクトです。指定しない場合は標準出力に出力されます。
@return nil を返します。
//emlist[][ruby]{
Object.new.display #=> #<Object:0xbb0210>
//}
@see $stdout -
Object
# public _ methods(include _ inherited = true) -> [Symbol] (36610.0) -
そのオブジェクトが理解できる public メソッド名の一覧を返します。
そのオブジェクトが理解できる public メソッド名の一覧を返します。
@param include_inherited 偽となる値を指定すると自身のクラスのスーパークラスで定義されたメソッドを除きます。
@see Module#public_instance_methods,Object#methods,Object#singleton_methods -
Object
# public _ send(name , *args) -> object (36610.0) -
オブジェクトの public メソッド name を args を引数にして呼び出し、メソッ ドの実行結果を返します。
オブジェクトの public メソッド name を args を引数にして呼び出し、メソッ
ドの実行結果を返します。
ブロック付きで呼ばれたときはブロックもそのまま引き渡します。
//emlist[][ruby]{
1.public_send(:+, 2) # => 3
//}
@param name 文字列かSymbol で指定するメソッド名です。
@param args 呼び出すメソッドに渡す引数です。
@raise ArgumentError name を指定しなかった場合に発生します。
@raise NoMethodError protected メソッドや priv... -
Object
# public _ send(name , *args) { . . . . } -> object (36610.0) -
オブジェクトの public メソッド name を args を引数にして呼び出し、メソッ ドの実行結果を返します。
オブジェクトの public メソッド name を args を引数にして呼び出し、メソッ
ドの実行結果を返します。
ブロック付きで呼ばれたときはブロックもそのまま引き渡します。
//emlist[][ruby]{
1.public_send(:+, 2) # => 3
//}
@param name 文字列かSymbol で指定するメソッド名です。
@param args 呼び出すメソッドに渡す引数です。
@raise ArgumentError name を指定しなかった場合に発生します。
@raise NoMethodError protected メソッドや priv... -
Rational
# marshal _ dump -> Array (36610.0) -
Marshal.#load のためのメソッドです。 Rational::compatible#marshal_load で復元可能な配列を返します。
Marshal.#load のためのメソッドです。
Rational::compatible#marshal_load で復元可能な配列を返します。
[注意] Rational::compatible は通常の方法では参照する事ができません。 -
RubyVM
:: InstructionSequence # absolute _ path -> String | nil (36610.0) -
self が表す命令シーケンスの絶対パスを返します。
self が表す命令シーケンスの絶対パスを返します。
self を文字列から作成していた場合は nil を返します。
例1:irb で実行した場合
iseq = RubyVM::InstructionSequence.compile('num = 1 + 2')
# => <RubyVM::InstructionSequence:<compiled>@<compiled>>
iseq.absolute_path
# => nil
例2: RubyVM::InstructionSequence.compile_file を使用した場合
# /tmp/method.... -
String
# each _ grapheme _ cluster -> Enumerator (36610.0) -
文字列の書記素クラスタに対して繰り返します。
文字列の書記素クラスタに対して繰り返します。
String#each_char と違って、
Unicode Standard Annex #29 (https://unicode.org/reports/tr29/)
で定義された書記素クラスタに対して繰り返します。
//emlist[例][ruby]{
"a\u0300".each_char.to_a.size # => 2
"a\u0300".each_grapheme_cluster.to_a.size # => 1
//}
@see String#grapheme_clusters -
String
# grapheme _ clusters -> [String] (36610.0) -
文字列の書記素クラスタの配列を返します。(self.each_grapheme_cluster.to_a と同じです)
文字列の書記素クラスタの配列を返します。(self.each_grapheme_cluster.to_a と同じです)
//emlist[例][ruby]{
"a\u0300".grapheme_clusters # => ["à"]
//}
ブロックが指定された場合は String#each_grapheme_cluster と同じように動作します。
Ruby 2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。
@see String#each_grapheme_cluster -
Symbol
# capitalize(*options) -> Symbol (36610.0) -
シンボルに対応する文字列の先頭の文字を大文字に、残りを小文字に変更した シンボルを返します。
シンボルに対応する文字列の先頭の文字を大文字に、残りを小文字に変更した
シンボルを返します。
(self.to_s.capitalize.intern と同じです。)
:foobar.capitalize #=> :Foobar
:fooBar.capitalize #=> :Foobar
:FOOBAR.capitalize #=> :Foobar
:"foobar--".capitalize # => "Foobar--"
@see String#capitalize -
Thread
:: Backtrace :: Location # absolute _ path -> String (36610.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
:: Mutex # sleep(timeout = nil) -> Integer (36610.0) -
与えられた秒数の間ロックを解除してスリープして、実行後にまたロックします。
与えられた秒数の間ロックを解除してスリープして、実行後にまたロックします。
@param timeout スリープする秒数を指定します。省略するとスリープし続けます。
@return スリープしていた秒数を返します。
@raise ThreadError 自身がカレントスレッドによってロックされていない場合に発生します。
[注意] 2.0 以降ではスリープ中でも、シグナルを受信した場合などに実行が再
開(spurious wakeup)される場合がある点に注意してください。
//emlist[例][ruby]{
m = Mutex.new
th = Thread.new do
... -
Complex
# angle -> Float (36310.0) -
自身の偏角を[-π,π]の範囲で返します。
自身の偏角を[-π,π]の範囲で返します。
//emlist[例][ruby]{
Complex.polar(3, Math::PI/2).arg # => 1.5707963267948966
//}
非正の実軸付近での挙動に注意してください。以下の例のように虚部が 0.0 と
-0.0 では値が変わります。
//emlist[例][ruby]{
Complex(-1, 0).arg #=> 3.141592653589793
Complex(-1, -0).arg #=> 3.141592653589793
Complex(-1... -
Enumerator
:: Lazy # flat _ map {|item| . . . } -> Enumerator :: Lazy (27910.0) -
ブロックの実行結果をひとつに繋げたものに対してイテレートするような Enumerator::Lazy のインスタンスを返します。
ブロックの実行結果をひとつに繋げたものに対してイテレートするような
Enumerator::Lazy のインスタンスを返します。
//emlist[][ruby]{
["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force
#=> ["f", "o", "o", "b", "a", "r"]
//}
ブロックの返した値 x は、以下の場合にのみ分解され、連結されます。
* x が配列であるか、to_ary メソッドを持つとき
* x が each および force メソッドを持つ (例:Enumerator::Lazy) ... -
Symbol
# casecmp?(other) -> bool | nil (27910.0) -
大文字小文字の違いを無視しシンボルを比較します。 シンボルが一致する場合には true を返し、一致しない場合には false を返します。
大文字小文字の違いを無視しシンボルを比較します。
シンボルが一致する場合には true を返し、一致しない場合には false を返します。
@param other 比較対象のシンボルを指定します。
//emlist[][ruby]{
:abcdef.casecmp?(:abcde) #=> false
:aBcDeF.casecmp?(:abcdef) #=> true
:abcdef.casecmp?(:abcdefg) #=> false
:abcdef.casecmp?(:ABCDEF) #=> true
:"\u{e4 f6 fc}".casecmp?... -
Float
# next _ float -> Float (27898.0) -
浮動小数点数で表現可能な self の次の値を返します。
浮動小数点数で表現可能な self の次の値を返します。
Float::MAX.next_float、Float::INFINITY.next_float は
Float::INFINITY を返します。Float::NAN.next_float は
Float::NAN を返します。
//emlist[例][ruby]{
p 0.01.next_float # => 0.010000000000000002
p 1.0.next_float # => 1.0000000000000002
p 100.0.next_float # => 100.00000000000001
p ... -
Enumerable
# zip(*lists) -> [[object]] (27700.0) -
self と引数に渡した配列の各要素からなる配列の配列を生成して返します。 生成される配列の要素数は self の要素数と同じです。
self と引数に渡した配列の各要素からなる配列の配列を生成して返します。
生成される配列の要素数は self の要素数と同じです。
ブロック付きで呼び出した場合は、
self と引数に渡した配列の各要素を順番にブロックに渡します。
@param lists 配列を指定します。配列でない場合は to_ary メソッドにより配列に変換します。
to_ary メソッドが無い場合は each を試します。
//emlist[例][ruby]{
p (1..3).zip([4,5,6], [7,8,9])
# => [[1, 4, 7], [2, 5, 8], [3,... -
Enumerable
# zip(*lists) {|v1 , v2 , . . . | . . . } -> nil (27700.0) -
self と引数に渡した配列の各要素からなる配列の配列を生成して返します。 生成される配列の要素数は self の要素数と同じです。
self と引数に渡した配列の各要素からなる配列の配列を生成して返します。
生成される配列の要素数は self の要素数と同じです。
ブロック付きで呼び出した場合は、
self と引数に渡した配列の各要素を順番にブロックに渡します。
@param lists 配列を指定します。配列でない場合は to_ary メソッドにより配列に変換します。
to_ary メソッドが無い場合は each を試します。
//emlist[例][ruby]{
p (1..3).zip([4,5,6], [7,8,9])
# => [[1, 4, 7], [2, 5, 8], [3,... -
TracePoint
# defined _ class -> Class | module (27664.0) -
メソッドを定義したクラスかモジュールを返します。
メソッドを定義したクラスかモジュールを返します。
//emlist[例][ruby]{
class C; def foo; end; end
trace = TracePoint.new(:call) do |tp|
p tp.defined_class # => C
end.enable do
C.new.foo
end
//}
メソッドがモジュールで定義されていた場合も(include に関係なく)モジュー
ルを返します。
//emlist[例][ruby]{
module M; def foo; end; end
class C; include M; end;
trac... -
Module
# private(*name) -> self (27646.0) -
メソッドを private に設定します。
メソッドを private に設定します。
引数なしのときは今後このクラスまたはモジュール定義内で新規に定義さ
れるメソッドを関数形式でだけ呼び出せるように(private)設定します。
引数が与えられた時には引数によって指定されたメソッドを private に
設定します。
可視性については d:spec/def#limit を参照して下さい。
@param name 0 個以上の String または Symbol を指定します。
@raise NameError 存在しないメソッド名を指定した場合に発生します。
//emlist[例][ruby]{
class Foo
... -
Symbol
# swapcase(*options) -> Symbol (27646.0) -
'A' から 'Z' までのアルファベット大文字を小文字に、'a' から 'z' までの アルファベット小文字を大文字に変更したシンボルを返します。
'A' から 'Z' までのアルファベット大文字を小文字に、'a' から 'z' までの
アルファベット小文字を大文字に変更したシンボルを返します。
(self.to_s.swapcase.intern と同じです。)
p :ABCxyz.swapcase # => :abcXYZ
p :Access.swapcase # => :aCCESS
@see String#swapcase -
Enumerator
:: Yielder # to _ proc -> Proc (27628.0) -
Enumerator.new で使うメソッドです。
Enumerator.new で使うメソッドです。
引数を Enumerator::Yielder#yield に渡す Proc を返します。
これは Enumerator::Yielder オブジェクトを他のメソッドにブロック引数と
して直接渡すために使えます。
//emlist[例][ruby]{
text = <<-END
Hello
こんにちは
END
enum = Enumerator.new do |y|
text.each_line(&y)
end
enum.each do |line|
p line
end
# => "Hello\n"
# "こんにちは... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (27628.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
バックトレース情報を返します。Exception#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。
現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。
//emlist[例: test.rb][ruby]{
require "date"
def check_long_month(month)
return if Date.new(2000, month, -1).day == 31
raise "#{month} is not long month"
end
... -
File
:: Stat # pipe? -> bool (27628.0) -
無名パイプおよび名前つきパイプ(FIFO)の時に真を返します。
無名パイプおよび名前つきパイプ(FIFO)の時に真を返します。
//emlist[][ruby]{
system("mkfifo /tmp/pipetest")
p File::Stat.new("/tmp/pipetest").pipe? #=> true
//} -
Proc
# to _ proc -> self (27628.0) -
self を返します。
self を返します。
//emlist[例][ruby]{
pr = proc {}
p pr == pr.to_proc # => true
//} -
ARGF
. class # codepoints { |c| . . . } -> self (27610.0) -
このメソッドは obsolete です。 代わりに ARGF.class#each_codepoint を使用してください。 使用すると警告メッセージが表示されます。
このメソッドは obsolete です。
代わりに ARGF.class#each_codepoint を使用してください。
使用すると警告メッセージが表示されます。 -
ARGF
. class # each _ codepoint { |c| . . . } -> self (27610.0) -
self の各コードポイントに対して繰り返しブロックを呼びだします。
self の各コードポイントに対して繰り返しブロックを呼びだします。
ブロックの引数にはコードポイントを表す整数が渡されます。
ブロックを省略した場合には、Enumerator を返します。
例:
# $ echo "line1\n" > test1.txt
# $ echo "line2\n" > test2.txt
# $ ruby test.rb test1.txt test2.txt
# test.rb
ARGF.each_codepoint # => #<Enumerator: ARGF:each_codepoint>
... -
ARGF
. class # print(*arg) -> nil (27610.0) -
引数を順に処理対象のファイルに出力します。
引数を順に処理対象のファイルに出力します。
c:ARGF#inplace時にのみ使用できます。
また $stdout への代入の影響を受けません。
それ以外は Kernel.#print と同じです。
@param arg 出力するオブジェクトを任意個指定します。 -
ARGF
. class # printf(format , *arg) -> nil (27610.0) -
C 言語の printf と同じように、format に従い引数を 文字列に変換して処理対象のファイルに出力します。
C 言語の printf と同じように、format に従い引数を
文字列に変換して処理対象のファイルに出力します。
c:ARGF#inplace時にのみ使用できます。
また $stdout への代入の影響を受けません。
それ以外は出力先を指定しない形式の Kernel.#printf と同じです。
@param format フォーマット文字列です。
@param arg フォーマットされる引数です。 -
ARGF
. class # puts(*arg) -> nil (27610.0) -
引数と改行を順番に処理対象のファイルに出力します。 引数がなければ改行のみを出力します。
引数と改行を順番に処理対象のファイルに出力します。
引数がなければ改行のみを出力します。
c:ARGF#inplace時にのみ使用できます。
また $stdout への代入の影響を受けません。
それ以外は Kernel.#puts と同じです。
@param arg 出力するオブジェクトを任意個指定します。 -
ARGF
. class # skip -> self (27610.0) -
現在開いている処理対象のファイルをクローズします。 次回の読み込みは次の引数が処理対象になります。 self を返します。
現在開いている処理対象のファイルをクローズします。
次回の読み込みは次の引数が処理対象になります。
self を返します。
$ echo "foo" > foo
$ echo "bar" > bar
$ ruby argf.rb foo bar
ARGF.filename # => "foo"
ARGF.skip
ARGF.filename # => "bar" -
Complex
# rationalize(eps) -> Rational (27610.0) -
自身を Rational に変換します。
自身を Rational に変換します。
@param eps 許容する誤差。常に無視されます。
@raise RangeError 虚部が実数か、0 ではない場合に発生します。
//emlist[例][ruby]{
Complex(3).to_r # => (3/1)
Complex(3, 2).to_r # => RangeError
//} -
Enumerator
:: Lazy # drop(n) -> Enumerator :: Lazy (27610.0) -
Enumerable#drop と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#drop と同じですが、配列ではなくEnumerator::Lazy を返します。
@param n 要素数を指定します。
@raise ArgumentError n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
1.step.lazy.drop(3)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:drop(3)>
1.step.lazy.drop(3).take(10).force
# => [4, 5, 6, 7, 8, 9, 10, 1... -
Enumerator
:: Lazy # grep(pattern) {|item| . . . } -> Enumerator :: Lazy (27610.0) -
Enumerable#grep と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#grep と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep(/\A(\d)\1+\z/)>
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/).... -
Enumerator
:: Lazy # grep _ v(pattern) {|item| . . . } -> Enumerator :: Lazy (27610.0) -
Enumerable#grep_v と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#grep_v と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep_v(/(\d).*\1/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep_v(/(\d).*\1/)>
(100..Float::INFINITY).lazy.map(&:to_s).grep_v(/(\d).*\1/).t... -
Enumerator
:: Lazy # zip(*lists) -> Enumerator :: Lazy (27610.0) -
Enumerable#zip と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#zip と同じですが、配列ではなくEnumerator::Lazy を返します。
ただし一貫性のため、ブロック付きで呼び出した場合は Enumerable#zip と
同じ挙動になります。
//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a".."z":cycle>)>
1.step.lazy.zip(('a'..'z').cycle)... -
Enumerator
:: Lazy # zip(*lists) {|v1 , v2 , . . . | . . . } -> nil (27610.0) -
Enumerable#zip と同じですが、配列ではなくEnumerator::Lazy を返します。
Enumerable#zip と同じですが、配列ではなくEnumerator::Lazy を返します。
ただし一貫性のため、ブロック付きで呼び出した場合は Enumerable#zip と
同じ挙動になります。
//emlist[例][ruby]{
1.step.lazy.zip(('a'..'z').cycle)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:zip(#<Enumerator: "a".."z":cycle>)>
1.step.lazy.zip(('a'..'z').cycle)... -
Exception
# exception -> self (27610.0) -
引数を指定しない場合は self を返します。引数を指定した場合 自身のコピー を生成し Exception#message 属性を error_message にして返します。
引数を指定しない場合は self を返します。引数を指定した場合 自身のコピー
を生成し Exception#message 属性を error_message にして返します。
Kernel.#raise は、実質的に、例外オブジェクトの exception
メソッドの呼び出しです。
@param error_message エラーメッセージを表す文字列を指定します。
//emlist[例][ruby]{
begin
# ... # 何か処理
rescue => e
raise e.exception("an error occurs during hogeho... -
File
:: Stat # grpowned? -> bool (27610.0) -
グループIDが実効グループIDと等しい時に真を返します。
グループIDが実効グループIDと等しい時に真を返します。
補助グループIDは考慮されません。
//emlist[][ruby]{
printf "%s %s\n", $:[0], File::Stat.new($:[0]).grpowned?
#例
#=> /usr/local/lib/site_ruby/1.8 false
printf "%s %s\n", $0, File::Stat.new($0).grpowned?
#例
#=> filestat.rb true
//}