Last active
February 13, 2016 01:07
-
-
Save theHamdiz/bd470eac699d4702f6f1 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
| module OS | |
| def windows? | |
| # use !object.nil? instead of object != nil | |
| !(/mingw|mswin|cygwin|bccwin|emx/ =~ RUBY_PLATFORM).nil? | |
| end | |
| def mac? | |
| # check for the darwin kernel name | |
| !(/darwin/ =~ RUBY_PLATFORM).nil? | |
| end | |
| def solaris? | |
| # what if the os was solaris? | |
| !(/sunos|solaris|bsd/ =~ RUBY_PLATFORM).nil? | |
| end | |
| def linux? | |
| # linux is either defined as linux or arch | |
| !(/linux|arch/ =~ RUBY_PLATFORM).nil? | |
| end | |
| def other? | |
| !linux? && !mac? && !windows? && !solaris? | |
| end | |
| def os | |
| return "Mac OS X" if mac? | |
| return "Linux OS" if linux? | |
| return "Solaris OS" if solaris? | |
| return "Windows OS" if windows? | |
| "Strange OS" if other? | |
| end | |
| end | |
| class JARVIS | |
| include OS | |
| def initialize(owner) | |
| @owner = owner | |
| end | |
| def greet | |
| puts "Hi #{@owner} from #{os}" | |
| end | |
| end | |
| jar = JARVIS.new("Ahmad Hamdi") | |
| jar.greet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment