銀の童子日記

    • Edit
    • Delete
    • Tags
    • Autopost

    4th April 2011

    {Ruby] 配列クラス(4)eachとeach_with_index - Rubyを勉強しようと思ってはじめた日記 - Rubyist

    each_with_index

    each_with_indexを使うと、インデックスもわかりつつ、配列の要素すべてにアクセスができる

    list = [1,12,34,14,5,6]
    list.each_with_index{|elem, i|
        print i+1, "番目の要素は", elem, "です\n"
    }

    結果

    1番目の要素は1です
    2番目の要素は12です
    3番目の要素は34です
    4番目の要素は14です
    5番目の要素は5です
    6番目の要素は6です
    via rubyist.g.hatena.ne.jp

    indexを取りつつのeach

    • views
    ruby
    • 0 responses
    • Like
    • Comment
  • inarin's Space

    8525 Views

    Picasa
  • Search

  • Sites I Like

    • お気に入り
  • Tags

    • wordpress (26)
    • posterous (20)
    • iphone (16)
    • windows (16)
    • facebook (11)
    • 3good (10)
    • freesoft (10)
    • lifehack (9)
    • twitter (9)
    • firefox (8)
    • inkscape (6)
    • ruby (6)
    • windows7 (6)
    • chrome (5)
    • neta (5)
    • eccube (4)
    • air (3)
    • git (3)
    • jquery (3)
    • mac (3)
    • simfree (3)
    • EC1400-41K (2)
    • bmobile (2)
    • dev (2)
    • domain (2)
    • drupal (2)
    • eclipse (2)
    • evernote (2)
    • gmail (2)
    • moe (2)
    • mysql (2)
    • tombloo (2)
    • toyama (2)
    • ネタ (2)
    • 東北地方太平洋沖地震 (2)
    • VirtualBox (1)
    • android (1)
    • cooking (1)
    • gadget (1)
    • gcal (1)
    • gimp (1)
    • gmap (1)
    • ikitai (1)
    • movabletype (1)
    • nice (1)
    • php (1)
    • roman (1)
    • skype (1)
    • sugoi (1)
    • thunderbird (1)
    • tumblr (1)
    • ubuntu (1)
    • webサービス (1)
    • xnview (1)
    • 富山 (1)
    • 自然 (1)
  • Get Updates

    Subscribe via RSS

Copyright 銀の童子日記

Posterous Themes by Obox Design