Skip to content

Instantly share code, notes, and snippets.

@janxious
Created April 14, 2011 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janxious/918928 to your computer and use it in GitHub Desktop.
Save janxious/918928 to your computer and use it in GitHub Desktop.
module SayHello
def hello
puts "hello from SayHello"
end
end
include SayHello
hello
Any of these should be runnable at the command line by ruby <filename>
include Math
puts sqrt(25)
module Herp
def herp
"herp"
end
end
class Derp
include Herp
end
puts Derp.new.herp
# you can use extend to add new class methods
module Home
def steal
"home"
end
end
class Score
extend Home
end
puts Score.steal
# what's going on with extend
module Inspector
def saywhat
self.inspect
end
end
class Derp
include Inspector
extend Inspector
end
puts Derp.new.saywhat
puts Derp.saywhat
module M
CONSTANT = "value"
end
class C
include M
end
class D
extend M
end
puts C::CONSTANT
puts D::CONSTANT # wha?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment