Created
August 31, 2013 05:01
-
-
Save gouravtiwari/6396316 to your computer and use it in GitHub Desktop.
include-extend-idiom
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 Goodness | |
| def great? | |
| @language == 'Ruby' | |
| end | |
| def self.included(base) | |
| base.extend ClassMethods | |
| def interesting | |
| 'there are thousands of spoken languages around the world' | |
| end | |
| end | |
| module ClassMethods | |
| def cool_languages | |
| %w{Ruby Perl Python Java JavaScript Erlang} | |
| end | |
| end | |
| end | |
| class TestLanguage | |
| include Goodness | |
| def initialize(language) | |
| @language = language | |
| end | |
| end | |
| p TestLanguage.new('Ruby').interesting | |
| p TestLanguage.cool_languages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment