Skip to content

Instantly share code, notes, and snippets.

@bodhi
Created March 25, 2015 02:50
Show Gist options
  • Save bodhi/3fde34d207d7d36532fe to your computer and use it in GitHub Desktop.
Save bodhi/3fde34d207d7d36532fe to your computer and use it in GitHub Desktop.
I can never remember the scoping rules for Ruby, so here's an example to remind me.
module A
module X
def x
"X::x"
end
end
end
# Won't search in A for X, so need to scope it.
class A::B
include X rescue nil # :(
include A::X
def b
x
end
end
puts A::B.new.x
module U
module Y
def y
"Y::y"
end
end
end
# Will search for Y in U
module U
class V
include Y
def v
y
end
end
end
puts U::V.new.y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment