種類
- インスタンスメソッド (12)
- 特異メソッド (2)
- クラス (1)
キーワード
- Numeric (1)
- chr (3)
- new (2)
-
primitive
_ convert (4) -
to
_ h (2)
検索結果
先頭5件
-
Integer
# ord -> Integer (54682.0) -
自身を返します。
自身を返します。
//emlist[][ruby]{
10.ord #=> 10
# String#ord
?a.ord #=> 97
//}
@see String#ord -
String
# ord -> Integer (54628.0) -
文字列の最初の文字の文字コードを整数で返します。
文字列の最初の文字の文字コードを整数で返します。
self が空文字列のときは例外を発生します。
@return 文字コードを表す整数
@raise ArgumentError self の長さが 0 のとき発生
//emlist[例][ruby]{
p "a".ord # => 97
//}
@see Integer#chr, String#chr -
Numeric (4417.0)
-
数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。
数値を表す抽象クラスです。Integer や Float などの数値クラス
は Numeric のサブクラスとして実装されています。
演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッドは、サブクラスで提供されているメソッド
(+, -, *, /, %) を利用して定義されるものがほとんどです。
つまり Numeric で定義されているメソッドは、Numeric のサブクラスとして新たに数値クラスを定義した時に、
演算メソッド(+, -, *, /, %, <=>, coerce)だけを定義すれ... -
Exception
# full _ message(highlight: true , order: :bottom) -> String (607.0) -
例外の整形された文字列を返します。
例外の整形された文字列を返します。
返される文字列は Ruby が捕捉されなかった例外を標準エラー出力に出力するときと
同じ形式です。
そのため、メソッド呼び出し時に $stderr が変更されておらず、$stderr.tty? が真の場合は
エスケープシーケンスによる文字装飾がついています。
@param highlight エスケープシーケンスによる文字装飾をつけるかどうかを指定します。
デフォルト値は Exception.to_tty? の返り値と同じです。
@param order :top か :bottom で指定する必要があります。
... -
Struct
. new(*args , keyword _ init: false) -> Class (607.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定できるのは後方互換... -
Struct
. new(*args , keyword _ init: false) {|subclass| block } -> Class (607.0) -
Struct クラスに新しいサブクラスを作って、それを返します。
Struct クラスに新しいサブクラスを作って、それを返します。
サブクラスでは構造体のメンバに対するアクセスメソッドが定義されています。
//emlist[例][ruby]{
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age = 6
printf "name:%s age:%d", fred.name, fred.age
#=> "name:fred age:6" を出力します
//}
実装の都合により、クラス名の省略は後づけの機能でした。
メンバ名に String を指定できるのは後方互換... -
Integer
# chr -> String (379.0) -
self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。
self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。
//emlist[][ruby]{
p 65.chr
# => "A"
p 12354.chr
# => `chr': 12354 out of char range (RangeError)
p 12354.chr(Encoding::UTF_8)
# => "あ"
p 12354.chr(Encoding::EUC_JP)
# => RangeError: invalid codepoint 0x3042 in EUC-JP
//}
引数無しで呼ばれた場合は self ... -
Integer
# chr(encoding) -> String (379.0) -
self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。
self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。
//emlist[][ruby]{
p 65.chr
# => "A"
p 12354.chr
# => `chr': 12354 out of char range (RangeError)
p 12354.chr(Encoding::UTF_8)
# => "あ"
p 12354.chr(Encoding::EUC_JP)
# => RangeError: invalid codepoint 0x3042 in EUC-JP
//}
引数無しで呼ばれた場合は self ... -
Encoding
:: Converter # primitive _ convert(source _ buffer , destination _ buffer) -> Symbol (361.0) -
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
可搬性を確保しつつ、不正なバイトや変換先で未定義な文字の扱いを細かに指定したいときは、Encoding::Converter#primitive_convert が唯一の方法になります。
@param source_buffer 変換元文字列のバッファ
@param destination_buffer 変換先文字列を格納するバッファ
@param destination_byteoffset 変換先バッファでのオフセット
@param destination_bytesize 変換先バッファの容量
@... -
Encoding
:: Converter # primitive _ convert(source _ buffer , destination _ buffer , destination _ byteoffset) -> Symbol (361.0) -
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
可搬性を確保しつつ、不正なバイトや変換先で未定義な文字の扱いを細かに指定したいときは、Encoding::Converter#primitive_convert が唯一の方法になります。
@param source_buffer 変換元文字列のバッファ
@param destination_buffer 変換先文字列を格納するバッファ
@param destination_byteoffset 変換先バッファでのオフセット
@param destination_bytesize 変換先バッファの容量
@... -
Encoding
:: Converter # primitive _ convert(source _ buffer , destination _ buffer , destination _ byteoffset , destination _ bytesize) -> Symbol (361.0) -
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
可搬性を確保しつつ、不正なバイトや変換先で未定義な文字の扱いを細かに指定したいときは、Encoding::Converter#primitive_convert が唯一の方法になります。
@param source_buffer 変換元文字列のバッファ
@param destination_buffer 変換先文字列を格納するバッファ
@param destination_byteoffset 変換先バッファでのオフセット
@param destination_bytesize 変換先バッファの容量
@... -
Encoding
:: Converter # primitive _ convert(source _ buffer , destination _ buffer , destination _ byteoffset , destination _ bytesize , options) -> Symbol (361.0) -
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
エンコーディング変換のためのメソッドの中で、もっとも細かな扱いが可能なメソッドです。
可搬性を確保しつつ、不正なバイトや変換先で未定義な文字の扱いを細かに指定したいときは、Encoding::Converter#primitive_convert が唯一の方法になります。
@param source_buffer 変換元文字列のバッファ
@param destination_buffer 変換先文字列を格納するバッファ
@param destination_byteoffset 変換先バッファでのオフセット
@param destination_bytesize 変換先バッファの容量
@... -
String
# chr -> String (361.0) -
self の最初の文字だけを含む文字列を返します。
self の最初の文字だけを含む文字列を返します。
//emlist[例][ruby]{
a = "abcde"
a.chr #=> "a"
//}
Ruby 1.9 で IO#getc の戻り値が Integer から String を返すように変更になりました。
Ruby 1.8 以前と1.9以降の互換性を保つために String#chr が存在します。
例:
# ruby 1.8 系では STDIN.getc が 116 を返すため Integer#chr が呼び出される
$ echo test | ruby -e "p STDIN.getc.chr" # => ... -
Array
# to _ h -> Hash (325.0) -
self を [key, value] のペアの配列として解析した結果を Hash にして 返します。
self を [key, value] のペアの配列として解析した結果を Hash にして
返します。
//emlist[例][ruby]{
bar], [1, 2.to_h # => {:foo => :bar, 1 => 2}
//}
ブロックを指定すると配列の各要素でブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
["foo", "bar"].to_h {|s| [s.ord, s]} # => {102=>"foo", 98=>"bar"}
//} -
Array
# to _ h { block } -> Hash (325.0) -
self を [key, value] のペアの配列として解析した結果を Hash にして 返します。
self を [key, value] のペアの配列として解析した結果を Hash にして
返します。
//emlist[例][ruby]{
bar], [1, 2.to_h # => {:foo => :bar, 1 => 2}
//}
ブロックを指定すると配列の各要素でブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
["foo", "bar"].to_h {|s| [s.ord, s]} # => {102=>"foo", 98=>"bar"}
//}