Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View 00-0-README
1 2 3 4 5 6 7 8 9
module SayHello
def hello
puts "hello from SayHello"
end
end
 
include SayHello
 
hello
View 00-0-README
1
Any of these should be runnable at the command line by ruby <filename>
View 00-0-README
1 2 3 4 5 6 7 8 9 10 11
module Herp
def herp
"herp"
end
end
 
class Derp
include Herp
end
 
puts Derp.new.herp
View 00-0-README
1 2 3 4 5 6 7 8 9 10 11 12
# you can use extend to add new class methods
module Home
def steal
"home"
end
end
 
class Score
extend Home
end
 
puts Score.steal
View 00-0-README
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# 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
View 00-0-README
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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.