ハロの外部記憶インターフェイス

そろそろ覚える努力が必要かも…

2014-08-22から1日間の記事一覧

Hashクラス

初期化 a = "a"=>"b", "c"=>"d"} Hash["a", "b", "c", "d"] #{"a"=>"b", "c"=>"d"} a = Hash.new("DD") a["first"] #="DD" a.default #="DD" a.default = "EE" a["first"] #="EE" a = Hash.new{|hash, key| hash[key] = nil} a.["a"] #=nil Hashのキーや値を…

組み込みモジュール

Comparableモジュール 比較(,=>,>)が出来るようにするモジュール インクルードとの実装が必要 class Foo include Comparable attr_accessor :num def initialize(num) @num = num end def <=>(other) return @num <=> other.num end end foo = Foo.new(10) b…