Parse Error

sugizou is Parse Error
<< ダーツ情報 - 関西版 | main | ruby,php,perlでmemcacheの中身を使い回す >>
スポンサーサイト
この広告は60日以上更新がないブログに表示されております。
新しい記事を書くことで広告を消すことができます。
| - | | - | - | pookmark |
linkedlist
CodeKata: Kata Twenty One: Simple Lists
勉強の一環として書いてみた。

lib/list.rb


require 'lib/node'

class List < Array

def initialize
@node_lists = []
end

def add(arg='')
node = Node.new
node.value = arg
node.prev = @node_lists.last
node.next = nil
@node_lists.last.next = node if @node_lists.length > 0
@node_lists << node
end

def find(arg)
@node_lists.find { |node| node.value == arg }
end

def values
@node_lists.map { |node| node.value }
end

def delete(node)
return nil if @node_lists.empty?

pos = @node_lists.index(node)
if @node_lists[pos+1].nil? || @node_lists[pos-1].nil?
@node_lists[pos-1].next = nil unless @node_lists[pos-1].nil?
@node_lists[pos+1].prev = nil unless @node_lists[pos+1].nil?
else
@node_lists[pos-1].next = @node_lists[pos+1]
@node_lists[pos+1].prev = @node_lists[pos-1]
end

@node_lists.delete_at(pos)
end

end

lib/node.rb


class Node

attr_accessor :value
attr_accessor :next
attr_accessor :prev

end

| ruby | 19:25 | comments(0) | trackbacks(0) | pookmark |
コメント
コメントする









この記事のトラックバックURL
http://sugizou.jugem.jp/trackback/131
トラックバック
CALENDAR
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
28293031   
<< August 2011 >>
SELECTED ENTRIES
CATEGORIES
ARCHIVES
モバイル
qrcode
LINKS
PROFILE