クラス
-
ARGF
. class (55) - Array (22)
- BasicObject (11)
- Class (11)
- Data (4)
-
Encoding
:: Converter (22) -
Encoding
:: InvalidByteSequenceError (11) -
Encoding
:: UndefinedConversionError (11) - Enumerator (33)
-
Enumerator
:: Lazy (10) -
File
:: Stat (11) - IO (11)
- Integer (11)
- Method (22)
- Module (90)
- Object (77)
-
RubyVM
:: AbstractSyntaxTree :: Node (6) -
RubyVM
:: InstructionSequence (66) - String (99)
- Struct (22)
- Thread (22)
-
Thread
:: Backtrace :: Location (11) -
Thread
:: Queue (27) -
Thread
:: SizedQueue (27) - ThreadGroup (11)
- TracePoint (6)
- UnboundMethod (10)
モジュール
- Enumerable (66)
キーワード
-
absolute
_ path (22) - add (11)
-
alias
_ method (11) -
base
_ label (11) -
bind
_ call (10) -
const
_ added (2) - convert (11)
- cycle (33)
- deconstruct (2)
-
deconstruct
_ keys (2) - deq (18)
- disasm (11)
- disassemble (11)
- dump (11)
- each (55)
-
each
_ line (22) -
enum
_ for (22) -
error
_ bytes (11) -
error
_ char (11) - gsub (44)
- inherited (11)
-
insert
_ output (11) - inspect (6)
-
instruction
_ sequence (6) - label (11)
-
max
_ by (44) -
method
_ added (11) -
method
_ removed (11) -
method
_ undefined (11) - next (11)
- owner (11)
- path (11)
- pop (18)
- prepend (11)
- prepended (11)
-
public
_ send (22) - refine (11)
-
respond
_ to? (11) - run (11)
- setuid? (11)
- shift (18)
-
singleton
_ method _ undefined (11) -
source
_ location (11) - sub (33)
- times (11)
-
to
_ enum (22) -
undef
_ method (11) - upto (11)
- wakeup (11)
-
with
_ index (10) -
with
_ object (22)
検索結果
先頭5件
-
IO
# puts(*obj) -> nil (24238.0) -
各 obj を self に出力し、それぞれの後に改行を出力します。 引数の扱いは Kernel.#puts と同じです。詳細はこちらを参照し てください。
...れぞれの後に改行を出力します。
引数の扱いは Kernel.#puts と同じです。詳細はこちらを参照し
てください。
@param obj 出力したいオブジェクトを指定します。Kernel.#puts と同じです。
@raise IOError 自身が書き込み用にオープン......されていなければ発生します。
@raise Errno::EXXX 出力に失敗した場合に発生します。
$stdout.puts("this", "is", "a", "test", [1, [nil, 3]])
#=>
this
is
a
test
1
3
@see Kernel.#puts... -
ARGF
. class # puts(*arg) -> nil (24210.0) -
引数と改行を順番に処理対象のファイルに出力します。 引数がなければ改行のみを出力します。
...力します。
引数がなければ改行のみを出力します。
c:ARGF#inplace時にのみ使用できます。
また $stdout への代入の影響を受けません。
それ以外は Kernel.#puts と同じです。
@param arg 出力するオブジェクトを任意個指定します。... -
Encoding
:: Converter # insert _ output(string) -> nil (12245.0) -
変換器内のバッファに文字列を挿入します。 バッファに保持された文字列は、次の変換時の変換結果と一緒に返されます。
...文字列
//emlist[][ruby]{
ec = Encoding::Converter.new("utf-8", "iso-8859-1")
src = "HIRAGANA LETTER A is \u{3042}."
dst = ""
p ec.primitive_convert(src, dst) #=> :undefined_conversion
puts "[#{dst.dump}, #{src.dump}]" #=> ["HIRAGANA LETTER A is ", "."]
ec.insert_output("<err>")
p ec.primiti......d
puts "[#{dst.dump}, #{src.dump}]" #=> ["HIRAGANA LETTER A is <err>.", ""]
ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
src = "\u{306F 3041 3068 2661 3002}" # U+2661 is not representable in iso-2022-jp
dst = ""
p ec.primitive_convert(src, dst) #=> :undefined_conversion
puts "[#{dst.du......mp}, #{src.dump}]" #=> ["\e$B$O$!$H".force_encoding("ISO-2022-JP"), "\xE3\ x80\x82"]
ec.insert_output "?" # state change required to output "?".
p ec.primitive_convert(src, dst) #=> :finished
puts "[#{dst.dump}, #{src.dump}]" #=> ["\e$B$O$!$H\e(B?\e$B!#\e(B".force_encoding(... -
Object
# enum _ for(method = :each , *args) -> Enumerator (6209.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
sz * n if sz
end... -
Object
# enum _ for(method = :each , *args) {|*args| . . . } -> Enumerator (6209.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
sz * n if sz
end... -
Object
# to _ enum(method = :each , *args) -> Enumerator (6209.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
sz * n if sz
end... -
Object
# to _ enum(method = :each , *args) {|*args| . . . } -> Enumerator (6209.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
sz * n if sz
end... -
TracePoint
# instruction _ sequence -> RubyVM :: InstructionSequence (6209.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 :scrip... -
String
# gsub(pattern , replace) -> String (6133.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 引数 repla......列が評価される時点ではまだ正規表現マッチが行われておらず、
$1 がセットされていないからです。
また、gsub では「\」が部分文字列との置き換えという特別な意味を持つため、
replace に「\」自身を入れたいときは
「\」......ある間違い][ruby]{
p 'xbbb-xbbb'.gsub(/x(b+)/, "#{$1}") # => "-" # NG
p 'xbbb-xbbb'.gsub(/x(b+)/, "\1") # => "1-1" # NG
p 'xbbb-xbbb'.gsub(/x(b+)/, "\\1") # => "bbb-bbb" # OK
p 'xbbb-xbbb'.gsub(/x(b+)/, '\1') # => "bbb-bbb" # OK
p 'xbbb-xbbb'.gsub(/x(b+)/, '\\1')... -
String
# sub(pattern , replace) -> String (6133.0) -
文字列中で pattern にマッチした最初の部分を 文字列 replace で置き換えた文字列を生成して返します。
...eplace pattern で指定した文字列と置き換える文字列
//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......列が評価される時点ではまだ正規表現マッチが行われておらず、
$1 がセットされていないからです。
また、sub では「\」が部分文字列との置き換えという特別な意味を持つため、
replace に「\」自身を入れたいときは
「\」......ある間違い][ruby]{
p 'xbbb-xbbb'.sub(/x(b+)/, "#{$1}") # => "-xbbb" # NG
p 'xbbb-xbbb'.sub(/x(b+)/, "\1") # => "1-xbbb" # NG
p 'xbbb-xbbb'.sub(/x(b+)/, "\\1") # => "bbb-xbbb" # OK
p 'xbbb-xbbb'.sub(/x(b+)/, '\1') # => "bbb-xbbb" # OK
p 'xbbb-xbbb'.sub(/x(b+)/, '\\1')...