Skip to content

Instantly share code, notes, and snippets.

@kasei-san
Created July 28, 2014 22:34
Show Gist options
  • Save kasei-san/e56a19e94c3258d162f7 to your computer and use it in GitHub Desktop.
Save kasei-san/e56a19e94c3258d162f7 to your computer and use it in GitHub Desktop.
ActiveSupport::Concern と、Module#concerning ref: http://qiita.com/kasei-san/items/c016c626836da09a5a70
関心事、関連、利害関係 など
irb(main):001:0> m = Member.new
=> #<Member:0x007f92cfae15c8>
irb(main):002:0> m.name = "二郎"
=> "二郎"
irb(main):003:0> m.default_name?
=> false
irb(main):004:0> m.name = "太郎"
=> "太郎"
irb(main):005:0> m.default_name?
=> true
module Human
extend ActiveSupport::Concern
included do
attr_accessor :name
def self.default_name
"太郎"
end
def default_name?
name == self.class.default_name
end
end
end
class Member
include Human
end
class Member
concerning :Human do
included do
attr_accessor :name
def self.default_name
"太郎"
end
def default_name?
name == self.class.default_name
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment