Created
May 7, 2009 07:17
-
-
Save ukstudio/107967 to your computer and use it in GitHub Desktop.
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
| # coding: utf-8 | |
| # 定数をモジュールにすることでグルーピングする試み | |
| class Foo | |
| module Statuses | |
| INVALID = 0 | |
| VALID = 1 | |
| end | |
| include Statuses | |
| def initialize(status_code) | |
| @status_code = status_code | |
| end | |
| def status | |
| case @status_code | |
| when INVALID | |
| 'だめです' | |
| when VALID | |
| '大丈夫です' | |
| end | |
| end | |
| end | |
| puts Foo.new(Foo::Statuses::INVALID).status | |
| puts Foo.new(Foo::Statuses::VALID).status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment