るりまサーチ

最速Rubyリファレンスマニュアル検索!
93件ヒット [1-93件を表示] (0.091秒)
トップページ > クエリ:a[x] > クエリ:CompatibilityError[x]

別のキーワード

  1. _builtin to_a
  2. matrix to_a
  3. to_a
  4. dbm to_a
  5. argf.class to_a

ライブラリ

クラス

検索結果

Encoding::CompatibilityError (24006.0)

2つのエンコーディング間に互換性がない場合に発生する例外。

...い場合に発生する例外。

エンコーディングの異なる文字列を連結しようとした場合などに発生します。

//emlist[例][ruby]{
"あ".encode("EUC-JP") + "あ".encode("UTF-8")
#=> Encoding::CompatibilityError: incompatible character encodings: EUC-JP and UTF-8
//}...

String#unicode_normalize(form = :nfc) -> String (6130.0)

self を NFC、NFD、NFKC、NFKD のいずれかの正規化形式で Unicode 正規化し た文字列を返します。

...Unicode 正規化し
た文字列を返します。

@param form 正規化形式を :nfc、:nfd、:nfkc、:nfkd のいずれかで指定しま
す。省略した場合は :nfc になります。

@raise Encoding::CompatibilityError self が Unicode 文字列ではない場合...
...GB18030、UCS_2BE、and UCS_4BE を含みます。

また、self が UTF-8 以外のエンコーディングであった場合は一度 UTF-8 に変
換してから正規化されるため、UTF-8 よりも遅くなっています。

//emlist[例][ruby]{
"a\u0300".unicode_normalize # => 'à...
..."a\u0300".unicode_normalize(:nfc) # => 'à' ("\u00E0" と同じ)
"\u00E0".unicode_normalize(:nfd) # => 'à' ("a\u0300" と同じ)
"\xE0".force_encoding('ISO-8859-1').unicode_normalize(:nfd)
# => Encoding::CompatibilityError raised
//}

@see String#unicode_normal...

String#unicode_normalized?(form = :nfc) -> bool (6124.0)

self が引数 form で指定された正規化形式で Unicode 正規化された文字列か どうかを返します。

...化された文字列か
どうかを返します。

@param form 正規化形式を :nfc、:nfd、:nfkc、:nfkd のいずれかで指定しま
す。省略した場合は :nfc になります。

@raise Encoding::CompatibilityError self が Unicode 文字列ではない場合...
...す。

//emlist[例][ruby]{
"a\u0300".unicode_normalized? # => false
"a\u0300".unicode_normalized?(:nfd) # => true
"\u00E0".unicode_normalized? # => true
"\u00E0".unicode_normalized?(:nfd) # => false
"\xE0".force_encoding('ISO-8859-1').unicode_normalized?...
...# => Encoding::CompatibilityError raised
//}

@see String#unicode_normalize, String#unicode_normalize!...

String#unicode_normalize!(form = :nfc) -> self (6118.0)

self を NFC、NFD、NFKC、NFKD のいずれかの正規化形式で Unicode 正規化し た文字列に置き換えます。

...が行なわれなくても self を返します。

@param form 正規化形式を :nfc、:nfd、:nfkc、:nfkd のいずれかで指定しま
す。省略した場合は :nfc になります。

@raise Encoding::CompatibilityError self が Unicode 文字列ではない場合...
...に発生します。

//emlist[例][ruby]{
text = "a\u0300"
text.unicode_normalize!(:nfc)
text == "\u00E0" # => true
text.unicode_normalize!(:nfd)
text == "a\u0300" # => true
//}

@see String#unicode_normalize, String#unicode_normalized?...

正規表現 (522.0)

正規表現 * metachar * expansion * char * anychar * string * str * quantifier * capture * grouping * subexp * selector * anchor * cond * option * encoding * comment * free_format_mode * absenceop * list * specialvar * references

...
* metachar
* expansion
* char
* anychar
* string
* str
* quantifier
* capture
* grouping
* subexp
* selector
* anchor
* cond
* option
* encoding
* comment
* free_format_mode
* absenceop
* list
* specialvar
* references


正規表現(regular expression)...
...場所であるかを知ることができます。

//emlist[][ruby]{
/pat/
%r{pat}
//}

などの正規表現リテラルや Regexp.new などで正規表現
オブジェクトを得ることができます。


===[a:metachar] メタ文字列とリテラル、メタ文字とエスケープ
正規...
...う/.encoding # => #<Encoding:UTF-8>
/abc/.encoding # => #<Encoding:US-ASCII>
/abc/u.encoding # => #<Encoding:UTF-8>
//}

正規表現のエンコーディングと文字列のエンコーディングが非互換で
ある場合、Encoding::CompatibilityError が発生します。

エンコーデ...

絞り込み条件を変える

String (120.0)

文字列のクラスです。 ヌル文字を含む任意のバイト列を扱うことができます。 文字列の長さにはメモリ容量以外の制限はありません。

...用も可能
<<-End
この行はヒアドキュメント (終端記号をインデントできる)
End

//}

===[a:mutable] 破壊的な変更

Ruby の String クラスは mutable です。
つまり、オブジェクト自体を破壊的に変更できます。

「破壊的な変更」とは...
...pcase! メソッドの使用例を以下に示します。

//emlist[例:String#upcase!][ruby]{
a
= "string"
b = a
a
.upcase!
p a # => "STRING"
p b # => "STRING"
//}

この例では、a に対してメソッドを呼んだにも関わらず b も変更されています。
これは、変数 a...
...結合][ruby]{
s = "いろは"
a
= s.encode("EUC-JP")
b = s.encode("UTF-8")
p a == b #=> false

s = "合".encode("EUC-JP")
p s + "\u{4f53}".encode("EUC-JP") #=> "合体"
p s + "\u{4f53}" #=> Encoding::CompatibilityError
//}

String#eql? はハッシュ...
...ト、ダブルクオートとの併用も可能
<<~End
この行のインデントは無視される
End
//}

===[a:mutable] 破壊的な変更

Ruby の String クラスは mutable です。
つまり、オブジェクト自体を破壊的に変更できます。

「破壊的な変更」とは...

多言語化 (102.0)

多言語化 Ruby は US-ASCII はもちろん、US-ASCII 以外の文字エンコーディングもサポートしています。 文字列の内部表現のエンコーディングは固定されておらず、 プログラマは目的に応じて使用するエンコーディングを選ぶことができます。

...多言語化
Ruby は US-ASCII はもちろん、US-ASCII 以外の文字エンコーディングもサポートしています。
文字列の内部表現のエンコーディングは固定されておらず、
プログラマは目的に応じて使用するエンコーディングを選ぶこ...
...ィングを指定すると、
Ruby スクリプトに非 ASCII 文字を使うことができます。(magic_comment)
文字列リテラルや正規表現リテラルだけでなく変数名、メソッド名、クラス名などにも
ASCII 文字を使うことができます。ただし文...
...ん。
例外 (Encoding::CompatibilityError) が発生します。

//emlist[][ruby]{
p Encoding::ISO_2022_JP.dummy? # => true
s = "漢字".encode("ISO-2022-JP")
p s[0] #=> "\e"
s + "b" #=> Encoding::CompatibilityError: incompatible character encodings: ISO-2022-JP and UTF-8
//}

またダミ...

Regexp#fixed_encoding? -> bool (48.0)

正規表現が任意の ASCII 互換エンコーディングとマッチ可能な時に false を返します。

... ASCII 互換エンコーディングとマッチ可能な時に false を返します。

//emlist[例][ruby]{
# -*- coding:utf-8 -*-

r = /a/
r.fixed_encoding? # => false
r.encoding # => #<Encoding:US-ASCII>
r =~ "\u{6666} a"...
...# => 2
r =~ "\xa1\xa2 a".force_encoding("euc-jp") # => 2
r =~ "abc".force_encoding("euc-jp") # => 0

r = /a/u
r.fixed_encoding? # => true
r.encoding # => #<Encoding:UTF-8>
r =~ "\u{6666} a"...
...# => 2
begin
r =~ "\xa1\xa2".force_encoding("euc-jp")
rescue => e
e.class # => Encoding::CompatibilityError
end
r =~ "abc".force_encoding("euc-jp") # => 0

r = /\u{6666}/
r.fixed_encoding? # => true
r.enco...