るりまサーチ

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

別のキーワード

  1. util u
  2. erb u
  3. matrix u
  4. _builtin koi8_u
  5. encoding koi8_u

検索結果

<< 1 2 3 ... > >>

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
u
nless 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
u
nless 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
u
nless 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
u
nless 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')...

絞り込み条件を変える

<< 1 2 3 ... > >>