Skip to content

Instantly share code, notes, and snippets.

@theHamdiz
Last active February 13, 2016 01:07
Show Gist options
  • Select an option

  • Save theHamdiz/bd470eac699d4702f6f1 to your computer and use it in GitHub Desktop.

Select an option

Save theHamdiz/bd470eac699d4702f6f1 to your computer and use it in GitHub Desktop.
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