Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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
Something went wrong with that request. Please try again.