ライブラリ
- ビルトイン (194)
キーワード
- % (12)
- == (12)
- === (12)
-
append
_ as _ bytes (1) - crypt (12)
-
delete
_ suffix (8) -
delete
_ suffix! (8) -
each
_ byte (24) -
each
_ line (24) -
end
_ with? (12) - prepend (21)
-
start
_ with? (12) - sum (12)
- unpack (12)
- upto (12)
検索結果
先頭5件
-
String
# end _ with?(*strs) -> bool (6239.0) -
self の末尾が strs のいずれかであるとき true を返します。
...ずれかであるとき true を返します。
@param strs パターンを表す文字列 (のリスト)
//emlist[例][ruby]{
"string".end_with?("ing") # => true
"string".end_with?("str") # => false
"string".end_with?("str", "ing") # => true
//}
@see String#start_with?......ます。
@param strs パターンを表す文字列 (のリスト)
//emlist[例][ruby]{
"string".end_with?("ing") # => true
"string".end_with?("str") # => false
"string".end_with?("str", "ing") # => true
//}
@see String#start_with?
@see String#delete_suffix, String#delete_... -
String
# append _ as _ bytes(*objects) -> self (6226.0) -
引数で与えたオブジェクトをバイト列として、self に破壊的に連結します。
...RY (ASCII-8BIT)>
s.append_as_bytes("い") # => "\xE3\x81\x82\xE3\x81\x84"
# s << "い" では連結できない
s << "い" # => "incompatible character encodings: BINARY (ASCII-8BIT) and UTF-8 (Encoding::CompatibilityError)
//}
//emlist[引数で整数を渡す例][ruby]{
t = ""
t.append_as_byte......s(0x61) # => "a"
t.append_as_bytes(0x3062) # => "ab"
//}
@see String#<<, String#concat... -
String
# prepend(*arguments) -> String (6209.0) -
複数の文字列を先頭に破壊的に追加します。
...複数の文字列を先頭に破壊的に追加します。
@param arguments 追加したい文字列を指定します。
//emlist[例][ruby]{
a = "!!!"
a.prepend # => "!!!"
a # => "!!!"
a = "!!!"
a.prepend "hello ", "world" # => "hello world!!!"
a # => "hello... -
String
# prepend(other _ str) -> String (6209.0) -
文字列 other_str を先頭に破壊的に追加します。
...文字列 other_str を先頭に破壊的に追加します。
@param other_str 追加したい文字列を指定します。
//emlist[例][ruby]{
a = "world"
a.prepend("hello ") # => "hello world"
a # => "hello world"
//}... -
String
# unpack(template) -> Array (486.0) -
Array#pack で生成された文字列を テンプレート文字列 template にしたがってアンパックし、 それらの要素を含む配列を返します。
...アンパックし、
それらの要素を含む配列を返します。
@param template pack テンプレート文字列
@return オブジェクトの配列
以下にあげるものは、Array#pack、String#unpack
のテンプレート文字の一覧です。テンプレート文......、整数サイズ非依存 (ネットワークプロトコルなどに適切)
//emlist{
n: big endian unsigned 16bit
N: big endian unsigned 32bit
v: little endian unsigned 16bit
V: little endian unsigned 32bit
//}
: エンディアン依存、整数サイズ依存 (C の構造体などに......に適切)
//emlist{
S>: big endian unsigned 16bit(nと同じ)
s>: big endian int16_t
s!>: big endian signed short
l<: little endian int32_t
l!<: little endian signed long
//}
=== 各テンプレート文字の説明
説明中、Array#pack と String#unpack で違いのあるものは......ックし、
それらの要素を含む配列を返します。
@param template pack テンプレート文字列
@return オブジェクトの配列
以下にあげるものは、Array#pack、String#unpack、String#unpack1
のテンプレート文字の一覧です。テンプレ... -
String
# %(args) -> String (240.0) -
printf と同じ規則に従って args をフォーマットします。
....#sprintf(self, *args) と同じです。
それ以外の場合は Kernel.#sprintf(self, args) と同じです。
@param args フォーマットする値、もしくはその配列
@return フォーマットされた文字列
//emlist[例][ruby]{
p "i = %d" % 10 # => "i = 10"
p "......するには `%%' とします。
以下それぞれの要素に関して説明します。
=== フラグ
フラグには #, +, ' '(スペース), -, 0 の5種類があります。
: #
2進、8進、16進の指示子(b, B, o, x, X) ではそれぞれプレフィック
スとして "0b", "0B",......ては、負数に対して "-"
を付加することを示します。
//emlist[][ruby]{
p sprintf("%d", 1) #=> "1"
p sprintf("%+d", 1) #=> "+1"
p sprintf("%x", -1) #=> "..f" # ".." は無限に f が続くことを表している
p sprintf("%+x", -1) #=> "-1"
//}
: ' '(スペース)
`+'... -
String
# delete _ suffix!(suffix) -> self | nil (150.0) -
self の末尾から破壊的に suffix を削除します。
...。
@param suffix 末尾から削除する文字列を指定します。
@return 削除した場合は self、変化しなかった場合は nil
//emlist[][ruby]{
"hello".delete_suffix!("llo") # => "he"
"hello".delete_suffix!("hel") # => nil
//}
@see String#chomp!
@see String#chop!
@see String#d......elete_prefix!
@see String#delete_suffix
@see String#end_with?... -
String
# delete _ suffix(suffix) -> String (150.0) -
文字列の末尾から suffix を削除した文字列のコピーを返します。
...
@param suffix 末尾から削除する文字列を指定します。
@return 文字列の末尾から suffix を削除した文字列のコピー
//emlist[][ruby]{
"hello".delete_suffix("llo") # => "he"
"hello".delete_suffix("hel") # => "hello"
//}
@see String#chomp
@see String#chop
@see String......#delete_prefix
@see String#delete_suffix!
@see String#end_with?... -
String
# crypt(salt) -> String (144.0) -
self と salt から暗号化された文字列を生成して返します。 salt には英数字、ドット (「.」)、スラッシュ (「/」) から構成される、 2 バイト以上の文字列を指定します。
...きです。
他にも 29297 などがあります。
注意:
* Ruby 2.6 から非推奨になったため、引き続き必要な場合は
string-crypt gem の使用を検討してください。
* crypt の処理は crypt(3) の実装に依存しています。
従って、crypt で......
@param salt 文字列を暗号化するための鍵となる文字列。
英数字・「.」・「/」のいずれかで構成される 2 バイト以上の文字列
//emlist[例][ruby]{
# パスワードの暗号化
salt = [rand(64),rand(64)].pack("C*").tr("\x00-\x3f","A-Za-z0-9......./")
passwd.crypt(salt)
# UNIX のログイン認証
require 'etc'
def valid_login?(user, password)
ent = Etc.getpwnam(user)
password.crypt(ent.passwd) == ent.passwd
end
p valid_login?("taro", "password") # => 真偽値が得られる
//}... -
String
# ==(other) -> bool (132.0) -
other が文字列の場合、String#eql? と同様に文字列の内容を比較します。
...合、String#eql? と同様に文字列の内容を比較します。
other が文字列でない場合、
other.to_str が定義されていれば
other == self の結果を返します。(ただし、 other.to_str は実行されません。)
そうでなければ false を返します。
@param......
@return true か false
//emlist[例][ruby]{
stringlike = Object.new
def stringlike.==(other)
"string" == other
end
p "string".eql?(stringlike) #=> false
p "string" == stringlike #=> false
def stringlike.to_str
raise
end
p "string".eql?(stringlike) #=> false
p "string" == stringl......ike #=> true
//}
@see String#eql?... -
String
# ===(other) -> bool (132.0) -
other が文字列の場合、String#eql? と同様に文字列の内容を比較します。
...合、String#eql? と同様に文字列の内容を比較します。
other が文字列でない場合、
other.to_str が定義されていれば
other == self の結果を返します。(ただし、 other.to_str は実行されません。)
そうでなければ false を返します。
@param......
@return true か false
//emlist[例][ruby]{
stringlike = Object.new
def stringlike.==(other)
"string" == other
end
p "string".eql?(stringlike) #=> false
p "string" == stringlike #=> false
def stringlike.to_str
raise
end
p "string".eql?(stringlike) #=> false
p "string" == stringl......ike #=> true
//}
@see String#eql?...