種類
- インスタンスメソッド (266)
- 特異メソッド (33)
- 変数 (14)
- クラス (11)
クラス
-
ARGF
. class (11) - Bignum (3)
-
Enumerator
:: Lazy (74) - Fixnum (3)
- Integer (32)
- Object (11)
-
Process
:: Status (11) - Range (11)
-
RubyVM
:: InstructionSequence (66) - String (77)
モジュール
- Kernel (14)
キーワード
-
$ -K (7) -
$ KCODE (7) - Numeric (11)
- [] (21)
-
absolute
_ path (11) -
base
_ label (11) - chunk (11)
- compile (11)
- gsub (44)
- label (11)
- new (22)
- path (11)
-
singleton
_ class (11) -
slice
_ after (20) -
slice
_ before (33) -
slice
_ when (10) - sub (33)
-
to
_ io (11)
検索結果
先頭5件
- Enumerator
:: Lazy # slice _ before(initial _ state) {|elt , state| bool } -> Enumerator :: Lazy - Enumerator
:: Lazy # slice _ before(pattern) -> Enumerator :: Lazy - Object
# singleton _ class -> Class - Numeric
- RubyVM
:: InstructionSequence . new(source , file = nil , path = nil , line = 1 , options = nil) -> RubyVM :: InstructionSequence
-
Enumerator
:: Lazy # slice _ before(initial _ state) {|elt , state| bool } -> Enumerator :: Lazy (14108.0) -
Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
...Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>
1.step.lazy.slice_before { |e| e % 3 == 0 }.t......ake(5).force
# => [[1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14]]
//}
@see Enumerable#slice_before... -
Enumerator
:: Lazy # slice _ before(pattern) -> Enumerator :: Lazy (14108.0) -
Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
...Enumerable#slice_before と同じですが、配列ではなく Enumerator::Lazy を返します。
//emlist[例][ruby]{
1.step.lazy.slice_before { |e| e.even? }
# => #<Enumerator::Lazy: #<Enumerator: #<Enumerator::Generator:0x00007f9f31844ce8>:each>>
1.step.lazy.slice_before { |e| e % 3 == 0 }.t......ake(5).force
# => [[1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14]]
//}
@see Enumerable#slice_before... -
Object
# singleton _ class -> Class (14108.0) -
レシーバの特異クラスを返します。 まだ特異クラスがなければ、新しく作成します。
...ーバが nil か true か false なら、それぞれ NilClass, TrueClass,
FalseClass を返します。
@raise TypeError レシーバが Integer、Float、Symbol の場合に発生します。
//emlist[][ruby]{
Object.new.singleton_class #=> #<Class:#<Object:0xb7ce1e24>>
String.singleton_class......#=> #<Class:String>
nil.singleton_class #=> NilClass
//}
@see Object#class... -
Numeric (14020.0)
-
数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。
...値を表す抽象クラスです。Integer や Float などの数値クラス
は Numeric のサブクラスとして実装されています。
演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッド......供されているメソッド
(+, -, *, /, %) を利用して定義されるものがほとんどです。
つまり Numeric で定義されているメソッドは、Numeric のサブクラスとして新たに数値クラスを定義した時に、
演算メソッド(+, -, *, /, %, <=>, coerce)......表しメソッド定義などではこの記法を利用します。
効率のため Numeric のメソッドと同じメソッドがサブクラスで再定義されている場合があります。
Numeric#coerce メソッドを使うことによって異なる数値クラス間で演算を行... -
RubyVM
:: InstructionSequence . new(source , file = nil , path = nil , line = 1 , options = nil) -> RubyVM :: InstructionSequence (11408.0) -
引数 source で指定した Ruby のソースコードを元にコンパイル済みの RubyVM::InstructionSequence オブジェクトを作成して返します。
...にコンパイル済みの
RubyVM::InstructionSequence オブジェクトを作成して返します。
@param source Ruby のソースコードを文字列で指定します。
@param file ファイル名を文字列で指定します。
@param path 引数 file の絶対パスファイル名を......。
@param line 引数 source の 1 行目の行番号を指定します。
@param options コンパイル時のオプションを true、false、Hash オブ
ジェクトのいずれかで指定します。詳細は
RubyVM::InstructionSequence.compile_option= を参......照
してください。
RubyVM::InstructionSequence.compile("a = 1 + 2")
# => <RubyVM::InstructionSequence:<compiled>@<compiled>>
@see RubyVM::InstructionSequence.compile_file... -
Integer
# [](nth) -> Integer (11204.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
...lf[nth] は 1 か 0
@return self[i, len] は (n >> i) & ((1 << len) - 1) と同じ
@return self[i..j] は (n >> i) & ((1 << (j - i + 1)) - 1) と同じ
@return self[i...j] は (n >> i) & ((1 << (j - i)) - 1) と同じ
@return self[i..] は (n >> i) と同じ
@return self[..j] は......raise ArgumentError self[..j] で n & ((1 << (j + 1)) - 1) が 0 以外のとき
@raise ArgumentError self[...j] で n & ((1 << j) - 1) が 0 以外のとき
//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010
a = 9**15
50.downto(0) {|n| print....../}
n[i] は (n >> i) & 1 と等価なので、負のインデックスは常に 0 を返します。
//emlist[][ruby]{
p 255[-1] # => 0
//}
//emlist[複数ビットの例][ruby]{
0b01001101[2, 4] #=> 0b0011
0b01001100[2..5] #=> 0b0011
0b01001100[2...6] #=> 0b0011
# ^^^^
//}
self[nth]=bit (... -
Integer
# [](nth , len) -> Integer (11204.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
...lf[nth] は 1 か 0
@return self[i, len] は (n >> i) & ((1 << len) - 1) と同じ
@return self[i..j] は (n >> i) & ((1 << (j - i + 1)) - 1) と同じ
@return self[i...j] は (n >> i) & ((1 << (j - i)) - 1) と同じ
@return self[i..] は (n >> i) と同じ
@return self[..j] は......raise ArgumentError self[..j] で n & ((1 << (j + 1)) - 1) が 0 以外のとき
@raise ArgumentError self[...j] で n & ((1 << j) - 1) が 0 以外のとき
//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010
a = 9**15
50.downto(0) {|n| print....../}
n[i] は (n >> i) & 1 と等価なので、負のインデックスは常に 0 を返します。
//emlist[][ruby]{
p 255[-1] # => 0
//}
//emlist[複数ビットの例][ruby]{
0b01001101[2, 4] #=> 0b0011
0b01001100[2..5] #=> 0b0011
0b01001100[2...6] #=> 0b0011
# ^^^^
//}
self[nth]=bit (... -
Integer
# [](range) -> Integer (11204.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
...lf[nth] は 1 か 0
@return self[i, len] は (n >> i) & ((1 << len) - 1) と同じ
@return self[i..j] は (n >> i) & ((1 << (j - i + 1)) - 1) と同じ
@return self[i...j] は (n >> i) & ((1 << (j - i)) - 1) と同じ
@return self[i..] は (n >> i) と同じ
@return self[..j] は......raise ArgumentError self[..j] で n & ((1 << (j + 1)) - 1) が 0 以外のとき
@raise ArgumentError self[...j] で n & ((1 << j) - 1) が 0 以外のとき
//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010
a = 9**15
50.downto(0) {|n| print....../}
n[i] は (n >> i) & 1 と等価なので、負のインデックスは常に 0 を返します。
//emlist[][ruby]{
p 255[-1] # => 0
//}
//emlist[複数ビットの例][ruby]{
0b01001101[2, 4] #=> 0b0011
0b01001100[2..5] #=> 0b0011
0b01001100[2...6] #=> 0b0011
# ^^^^
//}
self[nth]=bit (... -
Integer
# [](nth) -> Integer (11120.0) -
nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。
...かの数値
@return 1 か 0
//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010
a = 9**15
50.downto(0) {|n| print a[n] }
# => 000101110110100000111000011110010100111100010111001
//}
n[i] は (n >> i) & 1 と等価なので、負のイン......デックスは常に 0 を返します。
//emlist[][ruby]{
p 255[-1] # => 0
//}
self[nth]=bit (つまりビットの修正) がないのは、Numeric 関連クラスが
immutable であるためです。... -
String
# gsub(pattern , replace) -> String (11120.0) -
文字列中で pattern にマッチする部分全てを 文字列 replace で置き換えた文字列を生成して返します。
...指定した文字列と置き換える文字列
//emlist[例][ruby]{
p 'abcdefg'.gsub(/def/, '!!') # => "abc!!g"
p 'abcabc'.gsub(/b/, '<<\&>>') # => "a<<b>>ca<<b>>c"
p 'xxbbxbb'.gsub(/x+(b+)/, 'X<<\1>>') # => "X<<bb>>X<<bb>>"
p '2.5'.gsub('.', ',') # => "2,5"
//}
注意:
第 2......意味を持つため、
replace に「\」自身を入れたいときは
「\」を二重にエスケープしなければなりません。
//emlist[ひとつめの括弧の内容に置き換えるときによくある間違い][ruby]{
p 'xbbb-xbbb'.gsub(/x(b+)/, "#{$1}") # => "-" # NG
p......=> "bbb-bbb" # OK
p 'xbbb-xbbb'.gsub(/x(b+)/, '\1') # => "bbb-bbb" # OK
p 'xbbb-xbbb'.gsub(/x(b+)/, '\\1') # => "bbb-bbb" # OK
//}
//emlist[バックスラッシュを倍にするときによくある間違い][ruby]{
puts '\n'.gsub(/\\/, "\\\\") # => \n # NG
puts '\n'.gsub(/\\/... -
String
# sub(pattern , replace) -> String (11114.0) -
文字列中で pattern にマッチした最初の部分を 文字列 replace で置き換えた文字列を生成して返します。
...tern で指定した文字列と置き換える文字列
//emlist[例][ruby]{
p 'abcdefg'.sub(/def/, '!!') # => "abc!!g"
p 'abcabc'.sub(/b/, '<<\&>>') # => "a<<b>>cabc"
p 'xxbbxbb'.sub(/x+(b+)/, 'X<<\1>>') # => "X<<bb>>xbb"
//}
注意:
第 2 引数 replace に $1 を埋め込ん......意味を持つため、
replace に「\」自身を入れたいときは
「\」を二重にエスケープしなければなりません。
//emlist[ひとつめの括弧の内容に置き換えるときによくある間違い][ruby]{
p 'xbbb-xbbb'.sub(/x(b+)/, "#{$1}") # => "-xbbb" # NG
p......=> "bbb-xbbb" # OK
p 'xbbb-xbbb'.sub(/x(b+)/, '\1') # => "bbb-xbbb" # OK
p 'xbbb-xbbb'.sub(/x(b+)/, '\\1') # => "bbb-xbbb" # OK
//}
//emlist[バックスラッシュを倍にするときによくある間違い][ruby]{
puts '\n'.sub(/\\/, "\\\\") # => \n # NG
puts '\n'.sub(/\\/,... -
RubyVM
:: InstructionSequence # absolute _ path -> String | nil (11108.0) -
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.rb
def hello
puts "hello, world"
end
# irb
> iseq = RubyVM::InstructionSequence.compile_file('/tmp/method.rb')
> iseq.absolute_path # => "/tmp/method.rb"
@see RubyVM::InstructionSequence#path...