るりまサーチ

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

別のキーワード

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

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Encoding::Converter#insert_output(string) -> nil (12221.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...
...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.dum...
...p}, #{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("...

Enumerator::Lazy#enum_for(method = :each, *args) -> Enumerator::Lazy (9203.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...うに、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0...
...to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator...

Enumerator::Lazy#enum_for(method = :each, *args) {|*args| block} -> Enumerator::Lazy (9203.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...うに、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0...
...to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator...

Enumerator::Lazy#to_enum(method = :each, *args) -> Enumerator::Lazy (9203.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...うに、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0...
...to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator...

Enumerator::Lazy#to_enum(method = :each, *args) {|*args| block} -> Enumerator::Lazy (9203.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...うに、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0...
...to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator...

絞り込み条件を変える

Enumerable#sum(init=0) -> object (9103.0)

要素の合計を返します。

...selfが空の場合、initを返します。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum {|k, v| k * v } # => 50
(1..10).sum # => 55
(1..10).sum {|v| v * 2 } # => 110
('a'..'z').sum # => TypeError
//}

init 引数を明...
...す。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum([]) #=> [1, 10, 2, 20]
"a\nb\nc".each_line.lazy.map(&:chomp).sum("") #=> "abc"
[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
//}

"+" メソッドが再定義されている場合、Enumerable#sum は再定義を無視す...
...ることがあります(例えばInteger#+)。

@see Array#sum...

Enumerable#sum(init=0) {|e| expr } -> object (9103.0)

要素の合計を返します。

...selfが空の場合、initを返します。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum {|k, v| k * v } # => 50
(1..10).sum # => 55
(1..10).sum {|v| v * 2 } # => 110
('a'..'z').sum # => TypeError
//}

init 引数を明...
...す。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum([]) #=> [1, 10, 2, 20]
"a\nb\nc".each_line.lazy.map(&:chomp).sum("") #=> "abc"
[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
//}

"+" メソッドが再定義されている場合、Enumerable#sum は再定義を無視す...
...ることがあります(例えばInteger#+)。

@see Array#sum...

Module#included_modules -> [Module] (9103.0)

self にインクルードされているモジュールの配列を返します。

...self にインクルードされているモジュールの配列を返します。

//emlist[例][ruby]{
module Mixin
end

module Outer
include Mixin
end

Mixin.included_modules #=> []
Outer.included_modules #=> [Mixin]
//}

@see Module#ancestors...

Module#module_function() -> nil (9103.0)

メソッドをモジュール関数にします。

...返します。
引数なしの時は nil を返します。

@param name String または Symbol を 0 個以上指定します。

=== 注意
module_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プライベートメソッドとモジ...
...ジュール関数の別名は定義できません。

//emlist[例][ruby]{
module M
def foo
p "foo"
end
module_function :foo
alias bar foo
end

M.foo # => "foo"
M.bar # => undefined method `bar' for Foo:Module (NoMethodError)
//}

このコードでは、モジュール関数 foo...
...けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。

//emlist[例][ruby]{
module M
def foo
p "foo"
end

alias bar foo
module_function :foo, :bar
end

M.foo # => "foo"
M.bar # => "foo"
//}...

Module#module_function(*name) -> Array (9103.0)

メソッドをモジュール関数にします。

...返します。
引数なしの時は nil を返します。

@param name String または Symbol を 0 個以上指定します。

=== 注意
module_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プライベートメソッドとモジ...
...ジュール関数の別名は定義できません。

//emlist[例][ruby]{
module M
def foo
p "foo"
end
module_function :foo
alias bar foo
end

M.foo # => "foo"
M.bar # => undefined method `bar' for Foo:Module (NoMethodError)
//}

このコードでは、モジュール関数 foo...
...けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。

//emlist[例][ruby]{
module M
def foo
p "foo"
end

alias bar foo
module_function :foo, :bar
end

M.foo # => "foo"
M.bar # => "foo"
//}...

絞り込み条件を変える

Module#module_function(*name) -> self (9103.0)

メソッドをモジュール関数にします。

...てモジュール関数です。

self を返します。

@param name String または Symbol を 0 個以上指定します。

=== 注意
module_function はメソッドに「モジュール関数」という属性をつけるメ
ソッドではなく、プライベートメソッドとモジュ...
...ジュール関数の別名は定義できません。

//emlist[例][ruby]{
module M
def foo
p "foo"
end
module_function :foo
alias bar foo
end

M.foo # => "foo"
M.bar # => undefined method `bar' for Foo:Module (NoMethodError)
//}

このコードでは、モジュール関数 foo...
...けるには、
以下のように、先に別名を定義してから
それぞれをモジュール関数にしなければいけません。

//emlist[例][ruby]{
module M
def foo
p "foo"
end

alias bar foo
module_function :foo, :bar
end

M.foo # => "foo"
M.bar # => "foo"
//}...
<< 1 2 3 ... > >>