23. クラスマクロ
単なるクラスメソッドの呼び出し
class Book ActiveRecord::Base
has_many :releases
belongs_to :publisher
validates_presence_of :title, :author
end
23/50
24. ?クラス主義とMix-in
module ActiveRecord
class Base
# ...
Base.class_eval do
include ActiveRecord::Persistence
extend ActiveModel::Naming
extend QueryCache::ClassMethods
extend ActiveSupport::Benchmarkable
extend ActiveSupport::DescendantsTracker
include ActiveModel::Conversion
include Validations
24/50
34. ennnnnd
http://redmine.ruby-lang.org/issues/5054
module MyModule
class MyClass
def my_method
10.times do
if rand 0.5
p :small
ennnnnd # = Here
34/50
42. RSpec
テスト?の内部DSL
describe App do
context Access pages do
it should show index do
get '/'
last_response.body.should
match('Test Site')
end
end
end
42/50
43. 短缩メソッドの追加
特異メソッドの利?
def Page(id)
Page.get_by_fuzzy_slug(id.to_s)
end
Page(home)
43/50