Created
July 28, 2014 22:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
関心事、関連、利害関係 など |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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