Skip to content

Instantly share code, notes, and snippets.

@masassiez
masassiez / fizzbuzz.rb
Created January 25, 2012 15:20
FizzBuzzクラス
class FizzBuzz
def initialize( from = 1, to = 30 )
@from, @to = [ from, to ].minmax
block_given? ? yield( self ) : self
end
def spec( out, &cond )
( @specs ||= [] ) << lambda { |e| cond[ e ] ? out : nil }
end
@masassiez
masassiez / tips19.rb
Created January 22, 2012 02:13
Ruby1.9 tips
# String#bytes.to_aよりもString#unpack("C*")
@masassiez
masassiez / study.rb
Created January 18, 2012 08:13
勉強メモ
# 定数参照
### ・クラス/モジュールで定義された定数は、その定数が定義されたクラス/モジュールに格納される
### ・クラス/モジュール定義の外(トップレベル)で定義された定数は Object に格納される
### ・メソッドの中では定義できません
## ネスト
### ・定数はその定数が定義されたクラス/モジュール定義の中(メソッドやネストしたクラス/モジュールも含む)から参照できる
CONST = "TOP"
module A
CONST = "A"
end