ライブラリ
- ビルトイン (1974)
- abbrev (22)
- bigdecimal (11)
-
cgi
/ core (66) -
cgi
/ session (33) -
cgi
/ session / pstore (11) -
cgi
/ util (11) - coverage (22)
- csv (198)
- date (110)
- dbm (44)
- drb (33)
-
drb
/ extservm (11) - erb (14)
- etc (11)
- forwardable (44)
- gdbm (44)
- ipaddr (11)
- irb (11)
- json (198)
-
json
/ add / bigdecimal (22) -
json
/ add / complex (22) -
json
/ add / date (22) -
json
/ add / date _ time (22) -
json
/ add / exception (22) -
json
/ add / ostruct (22) -
json
/ add / range (22) -
json
/ add / rational (22) -
json
/ add / regexp (22) -
json
/ add / struct (22) -
json
/ add / symbol (22) -
json
/ add / time (22) - matrix (22)
-
minitest
/ unit (1) - mkmf (66)
-
net
/ http (110) -
net
/ imap (33) -
net
/ pop (11) - objspace (33)
- open-uri (33)
- open3 (99)
- openssl (55)
- optparse (66)
- ostruct (65)
- pathname (11)
- pstore (55)
- psych (12)
- rake (55)
- rbconfig (33)
-
rbconfig
/ sizeof (22) -
rdoc
/ code _ object (11) -
rdoc
/ context (22) -
rdoc
/ markdown / entities (11) -
rdoc
/ markup / to _ html _ crossref (11) -
rdoc
/ text (11) -
rdoc
/ top _ level (11) -
rexml
/ document (110) -
rexml
/ sax2listener (11) -
rexml
/ streamlistener (11) -
rinda
/ rinda (44) -
rinda
/ tuplespace (55) - rubygems (22)
-
rubygems
/ command (22) -
rubygems
/ commands / dependency _ command (11) -
rubygems
/ dependency _ installer (11) -
rubygems
/ dependency _ list (11) -
rubygems
/ remote _ fetcher (11) -
rubygems
/ requirement (11) -
rubygems
/ security (33) -
rubygems
/ source _ index (33) -
rubygems
/ source _ info _ cache (66) -
rubygems
/ spec _ fetcher (22) -
rubygems
/ specification (22) - sdbm (44)
- set (7)
- shell (6)
-
shell
/ command-processor (12) -
shell
/ filter (6) - sync (6)
-
syslog
/ logger (11) - tsort (85)
- uri (154)
-
webrick
/ accesslog (11) -
webrick
/ cgi (11) -
webrick
/ config (33) -
webrick
/ httpauth / htdigest (11) -
webrick
/ httpauth / htpasswd (11) -
webrick
/ httprequest (44) -
webrick
/ httpresponse (22) -
webrick
/ https (11) -
webrick
/ httpservlet / filehandler (11) -
webrick
/ httputils (44) -
webrick
/ server (11) -
webrick
/ ssl (22) - win32ole (11)
-
yaml
/ dbm (33) -
yaml
/ store (19)
クラス
- Array (100)
- BigDecimal (33)
- Bignum (3)
- CGI (44)
-
CGI
:: Cookie (11) -
CGI
:: Session :: FileStore (11) -
CGI
:: Session :: MemoryStore (11) -
CGI
:: Session :: NullStore (11) -
CGI
:: Session :: PStore (11) - CSV (154)
-
CSV
:: Row (22) -
CSV
:: Table (22) - Complex (22)
- Coverage (22)
- DBM (44)
-
DRb
:: DRbServer (22) -
DRb
:: ExtServManager (11) - Data (6)
- Date (121)
- DateTime (33)
- ERB (14)
-
Encoding
:: Converter (44) -
Enumerator
:: ArithmeticSequence (6) - Exception (22)
- Float (11)
- GDBM (44)
-
Gem
:: Command (22) -
Gem
:: Commands :: DependencyCommand (11) -
Gem
:: DependencyInstaller (11) -
Gem
:: DependencyList (11) -
Gem
:: RemoteFetcher (11) -
Gem
:: Requirement (11) -
Gem
:: SourceIndex (33) -
Gem
:: SourceInfoCache (66) -
Gem
:: SpecFetcher (22) -
Gem
:: Specification (22) - Hash (631)
- IO (154)
- IPAddr (11)
-
JSON
:: Parser (11) -
JSON
:: State (11) - KeyError (14)
- MatchData (22)
- Matrix (11)
- Method (11)
-
MiniTest
:: Unit (1) - Module (5)
-
Net
:: HTTP (11) -
Net
:: HTTPRequest (11) -
Net
:: HTTPResponse (22) -
Net
:: IMAP (33) -
Net
:: POP3 (11) - Numeric (11)
- Object (33)
-
OpenSSL
:: SSL :: SSLContext (11) -
OpenSSL
:: X509 :: ExtensionFactory (33) -
OpenSSL
:: X509 :: Name (11) - OpenStruct (87)
- OptionParser (44)
- PStore (55)
- Pathname (11)
- Proc (16)
-
RDoc
:: CodeObject (11) -
RDoc
:: Context (22) -
RDoc
:: Markdown (11) -
RDoc
:: Markup :: ToHtmlCrossref (11) -
RDoc
:: Options (11) -
RDoc
:: TopLevel (11) -
REXML
:: Attributes (11) -
REXML
:: DocType (22) -
REXML
:: Document (11) -
REXML
:: Element (44) -
REXML
:: XPath (22) -
Rake
:: TaskArguments (55) - Range (33)
- Rational (33)
- Regexp (44)
-
Rinda
:: TupleEntry (11) -
Rinda
:: TupleSpace (44) -
Rinda
:: TupleSpaceProxy (44) -
RubyVM
:: InstructionSequence (55) - SDBM (44)
- Set (7)
- Shell (6)
-
Shell
:: CommandProcessor (12) -
Shell
:: Filter (6) - String (220)
- Struct (63)
- Symbol (22)
-
Syslog
:: Logger (11) - Thread (11)
- Time (33)
-
URI
:: FTP (22) -
URI
:: Generic (44) -
URI
:: HTTP (22) -
URI
:: LDAP (22) -
URI
:: MailTo (22) - UnboundMethod (22)
- Vector (11)
-
WEBrick
:: CGI (11) -
WEBrick
:: GenericServer (11) -
WEBrick
:: HTTPAuth :: Htdigest (11) -
WEBrick
:: HTTPAuth :: Htpasswd (11) -
WEBrick
:: HTTPRequest (44) -
WEBrick
:: HTTPResponse (22) -
WEBrick
:: HTTPServlet :: FileHandler (11) - WIN32OLE (11)
-
YAML
:: DBM (33) -
YAML
:: Store (19)
モジュール
- Abbrev (11)
-
CGI
:: QueryExtension (33) - DRb (11)
- Enumerable (71)
- Etc (11)
- Forwardable (22)
- GC (38)
-
GC
:: Profiler (11) -
Gem
:: QuickLoader (22) -
Gem
:: Security (33) - IRB (11)
- JSON (44)
-
JSON
:: Generator :: GeneratorMethods :: Array (11) -
JSON
:: Generator :: GeneratorMethods :: FalseClass (11) -
JSON
:: Generator :: GeneratorMethods :: Float (11) -
JSON
:: Generator :: GeneratorMethods :: Hash (11) -
JSON
:: Generator :: GeneratorMethods :: Integer (11) -
JSON
:: Generator :: GeneratorMethods :: NilClass (11) -
JSON
:: Generator :: GeneratorMethods :: Object (11) -
JSON
:: Generator :: GeneratorMethods :: String (33) -
JSON
:: Generator :: GeneratorMethods :: String :: Extend (11) -
JSON
:: Generator :: GeneratorMethods :: TrueClass (11) - Kernel (231)
- Marshal (22)
-
Net
:: HTTPHeader (66) - ObjectSpace (44)
- Open3 (99)
- OpenURI (22)
-
OpenURI
:: Meta (11) -
OptionParser
:: Arguable (11) - Psych (12)
-
RDoc
:: Text (11) -
REXML
:: SAX2Listener (11) -
REXML
:: StreamListener (11) - RbConfig (55)
- SingleForwardable (22)
-
Sync
_ m (6) - TSort (85)
- URI (22)
-
WEBrick
:: AccessLog (11) -
WEBrick
:: Config (66) -
WEBrick
:: HTTPUtils (33)
オブジェクト
- ENV (174)
キーワード
- % (11)
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - < (9)
- << (11)
- <= (9)
- == (11)
- === (11)
- > (9)
- >= (9)
- BasicAuth (11)
-
CODE
_ CLASS _ TO _ OBJ (11) -
CODE
_ TO _ OBJ (11) - CONFIG (22)
- Converters (11)
-
DEFAULT
_ ENTITIES (11) -
DEFAULT
_ OPTIONS (11) - DefaultMimeTypes (11)
- DigestAuth (11)
- Enumerable (11)
- FileHandler (11)
- FormData (11)
- GemPaths (11)
- GemVersions (11)
- General (11)
-
HTML
_ ENTITIES (11) - HTTP (11)
- HandlerTable (11)
- HeaderConverters (11)
-
LEVEL
_ MAP (11) - LIMITS (11)
-
MAKEFILE
_ CONFIG (11) -
MARSHAL
_ FIELDS (11) - Marshal フォーマット (11)
-
NEWS for Ruby 2
. 0 . 0 (11) -
NEWS for Ruby 2
. 1 . 0 (11) -
NEWS for Ruby 2
. 2 . 0 (10) -
NEWS for Ruby 2
. 3 . 0 (9) -
NEWS for Ruby 2
. 4 . 0 (8) -
NEWS for Ruby 2
. 5 . 0 (7) -
NEWS for Ruby 2
. 6 . 0 (6) -
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) - Numeric (11)
- OPS (11)
- OPT (11)
- OptionParser (11)
-
PATH
_ SEPARATOR (11) - Policies (11)
- Ruby用語集 (11)
-
SCRIPT
_ LINES _ _ (11) - SIZEOF (11)
-
SPECIFICATION
_ VERSION _ HISTORY (11) - SSL (11)
-
TABLE
_ FOR _ ESCAPE _ HTML _ _ (11) - [] (23)
-
_ httpdate (11) -
_ iso8601 (11) -
_ jisx0301 (11) -
_ parse (11) -
_ rfc2822 (11) -
_ rfc3339 (11) -
_ rfc822 (11) -
_ strptime (22) -
_ xmlschema (11) - abbrev (22)
-
add
_ attributes (11) -
add
_ class _ or _ module (22) -
add
_ element (11) -
add
_ specs (11) -
alias
_ map (6) - assoc (22)
- attributes (11)
- build (110)
- build2 (22)
-
build
_ self _ signed _ cert (11) -
cache
_ data (22) - cgi (11)
- clear (11)
- collect (24)
- command (11)
-
compare
_ by _ identity (11) -
compare
_ by _ identity? (11) - compile (11)
-
compile
_ file (11) -
compile
_ option (11) - conf (11)
- config (44)
- context (11)
-
count
_ nodes (11) -
count
_ objects (11) -
count
_ objects _ size (11) -
count
_ tdata _ objects (11) -
create
_ ext _ from _ hash (11) -
create
_ extension (22) -
decode
_ www _ form (11) -
deconstruct
_ keys (2) -
default
_ proc (11) - delegate (22)
- delete (11)
-
delete
_ if (11) - difference (6)
- dig (27)
- dump (22)
- each (77)
-
each
_ key (11) -
each
_ pair (22) -
each
_ strongly _ connected _ component (21) -
each
_ strongly _ connected _ component _ from (21) -
each
_ value (11) - encode (33)
-
encode
_ www _ form (11) - entities (11)
- eql? (55)
- equal? (11)
- exec (44)
- fetch (55)
-
fetch
_ path (11) - files (11)
- filter (24)
- filter! (24)
-
find
_ gems (11) - flatten (11)
- foreach (11)
-
form
_ data= (11) - format (11)
-
from
_ state (11) - generate (22)
-
generate
_ line (11) - getopts (55)
-
group
_ by (22) - gsub (44)
- gsub! (44)
-
handle
_ interrupt (11) - hash (231)
-
hash
_ old (11) - header (33)
- inspect (33)
-
instance
_ delegate (11) - intersection (5)
- invert (55)
- invoke (11)
-
irb
/ completion (11) -
json
_ create (143) -
keep
_ if (34) - key (7)
-
latest
_ cache _ data (11) -
latest
_ gc _ info (11) -
latest
_ specs (11) - length (11)
-
load
_ mime _ types (11) - map (24)
- match (11)
- member? (11)
- merge (22)
- merge! (22)
- modifiable (11)
-
named
_ captures (22) - namespaces (11)
- new (132)
- open (22)
-
open
_ uri (22) - optparse (11)
- owner (11)
- params (11)
- parse (44)
-
parse
_ header (11) -
parse
_ line (11) -
peek
_ result (11) - pipeline (11)
-
pipeline
_ r (22) -
pipeline
_ rw (22) -
pipeline
_ start (22) -
pipeline
_ w (22) - popen (154)
-
post
_ form (11) -
pretty
_ generate (11) -
pretty
_ unparse (11) -
primitive
_ convert (44) -
process
_ args (1) - query (11)
- rassoc (22)
-
raw
_ data (11) - rdoc (11)
- read (33)
-
read
_ all (22) -
read
_ cache _ data (11) - readlines (11)
- receiver (7)
- rehash (40)
- reject (88)
- reject! (22)
- replace (66)
- reset (7)
-
reset
_ cache _ for (11) - restore (44)
- result (18)
-
result
_ with _ hash (7) -
rexml
/ parsers / pullparser (11) -
rexml
/ parsers / ultralightparser (11) -
rm
_ f (11) -
rm
_ rf (11) - root? (11)
- roots (11)
- rss (11)
-
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 2 feature (11) -
ruby 1
. 8 . 4 feature (11) -
ruby 1
. 9 feature (11) -
ruby2
_ keywords (10) -
ruby2
_ keywords _ hash? (5) -
safe
_ load (12) - select (45)
- select! (34)
-
set
_ cache _ data (11) -
set
_ form _ data (11) -
set
_ params (11) -
setup
_ params (11) -
show
_ hash (11) -
single
_ delegate (11) - size (11)
- spawn (44)
-
spec
_ predecessors (11) -
specific
_ extra _ args _ hash (11) - specs (11)
- sprintf (11)
- sprintf フォーマット (11)
-
ssl
_ params (11) -
start
_ element (11) -
start
_ service (11) - starttls (22)
- stat (22)
- store (11)
-
strip
_ hashes (11) -
strongly
_ connected _ components (11) - sub (33)
- sub! (33)
-
sync
_ sh _ locker (6) - system (44)
- table (11)
-
tag
_ start (11) - take (22)
- tally (8)
-
to
_ a (22) -
to
_ csv (11) -
to
_ h (65) -
to
_ hash (22) -
to
_ json (231) -
to
_ json _ raw (11) -
to
_ json _ raw _ object (11) -
to
_ proc (9) -
to
_ s (44) -
transform
_ keys (17) -
transform
_ keys! (17) -
transform
_ values (16) -
transform
_ values! (16) -
try
_ convert (11) -
try
_ do (22) - tsort (22)
-
tsort
_ each (21) -
type
_ params (11) - uname (11)
- union (6)
-
unmatched
_ alias _ lists (11) - unparse (11)
- update (44)
- value (11)
-
verify
_ compaction _ references (5) -
webrick
/ cgi (11) -
with
_ defaults (11) - write (22)
- xmlrpc (3)
- xsystem (11)
- yaml (11)
- | (11)
- メソッド呼び出し(super・ブロック付き・yield) (11)
- リテラル (11)
検索結果
先頭5件
-
Hash
. ruby2 _ keywords _ hash?(hash) -> bool (33414.0) -
Module#ruby2_keywordsやProc#ruby2_keywordsによる ruby2_keywords フラグが設定されているかどうかを返します。
...Module#ruby2_keywordsやProc#ruby2_keywordsによる
ruby2_keywords フラグが設定されているかどうかを返します。
このメソッドはデバッグや調査、シリアライゼーションのために本当に必要な場合のために
用意されていて、普通のプログ......れていません。
ruby 2.7.1 で追加されたため、ruby 2.7.0 では定義されていません。
//emlist[][ruby]{
ruby2_keywords def foo(*args)
Hash.ruby2_keywords_hash?(args.last)
end
foo(k: 1) # => true
foo({k: 1}) # => false
//}
@see Module#ruby2_keywords, Proc#ruby2_keywords... -
Hash
# rehash -> self (33312.0) -
キーのハッシュ値を再計算します。
...@raise RuntimeError Hash#eachなどのイテレータの評価途中でrehashすると発生します。
@return selfを返します。
//emlist[例][ruby]{
a = [ "a", "b" ]
h = { a => 100 }
p h[a] #=> 100
a[0] = "z"
p h[a] #=> nil
h.rehash
p h[a] #=> 100
//}
@see Object#hash... -
Hash
# transform _ keys(hash) -> Hash (27427.0) -
すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。
...。
@param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。
//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys(&......:to_s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}
@see Hash#transform_keys!
@see Hash#transform_values
@see Hash#transform_values!... -
Hash
# merge(*others) -> Hash (27344.0) -
selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。 デフォルト値はselfの設定のままです。
...selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。
デフォルト値はselfの設定のままです。
self と others に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブ......に others の値を使います。
othersがハッシュではない場合、othersのメソッドto_hashを使って暗黙の変換を試みます。
@param others マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マー......d" => 400 }
h1.merge #=> {"a"=>100, "b"=>200}
h1.merge(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
h1.merge(h2, h3) #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
h1.merge(h2) {|key, oldval, newval| newval - oldval}
#=> {"a"=>100, "b"=>46, "c"=>300}
h1.merge(h2, h3) {|key,... -
Hash
# merge(*others) {|key , self _ val , other _ val| . . . } -> Hash (27344.0) -
selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。 デフォルト値はselfの設定のままです。
...selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。
デフォルト値はselfの設定のままです。
self と others に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブ......に others の値を使います。
othersがハッシュではない場合、othersのメソッドto_hashを使って暗黙の変換を試みます。
@param others マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マー......d" => 400 }
h1.merge #=> {"a"=>100, "b"=>200}
h1.merge(h2) #=> {"a"=>100, "b"=>246, "c"=>300}
h1.merge(h2, h3) #=> {"a"=>100, "b"=>357, "c"=>300, "d"=>400}
h1.merge(h2) {|key, oldval, newval| newval - oldval}
#=> {"a"=>100, "b"=>46, "c"=>300}
h1.merge(h2, h3) {|key,... -
Hash
# merge(other) -> Hash (27338.0) -
selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。
...selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。
self と other に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブロックを......に other の値を使います。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。
@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージ......した結果を返します
//emlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge() # => {"a"=>100, "b"=>200}
h1.merge(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1.merge(h2){|key, oldval, newval| newval - oldval}
# => {"a"=>100, "b"=>54, "c"=... -
Hash
# merge(other) {|key , self _ val , other _ val| . . . } -> Hash (27338.0) -
selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。
...selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。
self と other に同じキーがあった場合はブロック付きか否かで
判定方法が違います。ブロック付きのときはブロックを......に other の値を使います。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。
@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージ......した結果を返します
//emlist[][ruby]{
h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h1.merge() # => {"a"=>100, "b"=>200}
h1.merge(h2) # => {"a"=>100, "b"=>254, "c"=>300}
h1.merge(h2){|key, oldval, newval| newval - oldval}
# => {"a"=>100, "b"=>54, "c"=... -
Hash
# default _ proc -> Proc | nil (27330.0) -
ハッシュのデフォルト値を返す Proc オブジェクトを返します。 ハッシュがブロック形式のデフォルト値を持たない場合 nil を返します。
...Proc オブジェクトを返します。
ハッシュがブロック形式のデフォルト値を持たない場合 nil を返します。
//emlist[例][ruby]{
h = Hash.new {|hash, key| "The #{key} not exist in #{hash.inspect}"}
p h.default #=> nil
p block = h.default_proc #=> #<Pro......c:0x0x401a9ff4>
p block.call({},:foo) #=> "The foo not exist in {}"
h = Hash.new("default")
p h.default #=> "default"
p h.default_proc #=> nil
//}
@see Hash#default... -
Hash
. try _ convert(obj) -> Hash | nil (27329.0) -
to_hash メソッドを用いて obj をハッシュに変換しようとします。
...to_hash メソッドを用いて obj をハッシュに変換しようとします。
何らかの理由で変換できないときには nil を返します。
このメソッドは引数がハッシュであるかどうかを調べるために使えます。
//emlist[][ruby]{
Hash.try_convert({......1=>2}) # => {1=>2}
Hash.try_convert("1=>2") # => nil
//}... -
Hash
# transform _ keys -> Enumerator (27327.0) -
すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。
...。
@param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。
//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys(&......:to_s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}
@see Hash#transform_keys!
@see Hash#transform_values
@see Hash#transform_values!... -
Hash
# transform _ keys {|key| . . . } -> Hash (27327.0) -
すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。
...。
@param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。
//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys(&......:to_s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}
@see Hash#transform_keys!
@see Hash#transform_values
@see Hash#transform_values!... -
Hash
# invert -> Hash (27325.0) -
値からキーへのハッシュを作成して返します。
...st[例][ruby]{
h = { "a" => 0, "b" => 100, "c" => 200, "d" => 300, "e" => 300 }
p h.invert #=> {0=>"a", 100=>"b", 200=>"c", 300=>"e"}
//}
=== 参考
値が重複していたときに備えて、変換後の値を配列として保持するには、次のようにします。
//emlist[][ruby]{
de......f safe_invert(orig_hash)
orig_hash.each_key.group_by do |key|
orig_hash[key]
end
end
p safe_invert({"a"=>1, "b"=>1, "c"=>3}) # => {1=>["a", "b"], 3=>["c"]}
//}
@see Hash#key... -
Hash
# reject {|key , value| . . . } -> Hash (27325.0) -
self を複製して、ブロックを評価した値が真になる要 素を削除したハッシュを返します。
...Enumerable#reject とほぼ同じです。
selfを破壊的に変更したい場合はかわりにHash#delete_ifかHash#reject!を使います。
//emlist[例][ruby]{
h = { 2 =>"8" ,4 =>"6" ,6 =>"4" ,8 =>"2" }
p h.reject{|key, value| key.to_i < value.to_i} #=> {6=>"4", 8=>"2"}
//}
@see Hash#dele......te_if,Hash#delete,Enumerable#reject... -
Hash
# transform _ keys! -> Enumerator (27325.0) -
すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。
...@param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。
@return transform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。
//emlist[例][ruby......]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys!(&:to_sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }......# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}
@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_values!... -
Hash
# transform _ keys!(hash) -> self (27325.0) -
すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。
...@param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。
@return transform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。
//emlist[例][ruby......]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys!(&:to_sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }......# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}
@see Hash#transform_keys
@see Hash#transform_values
@see Hash#transform_values!... -
Hash
# transform _ keys -> Enumerator (27319.0) -
すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。
...ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(&:to_s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}
@see Hash#transfor......m_keys!
@see Hash#transform_values
@see Hash#transform_values!...