Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.