Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active September 16, 2015 01:05
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 YumaInaura/17a018aed4de0226e636 to your computer and use it in GitHub Desktop.
Save YumaInaura/17a018aed4de0226e636 to your computer and use it in GitHub Desktop.
Ruby: 絶対パスでメソッドを呼び出す。 ref: http://qiita.com/Yinaura/items/bbad6d788f2a0d5463f0
class Book
def self.example
p 'Class'
end
end
module Example
class Book
#このモジュールの example を呼ぶ
def self.call_module_method
Book.example
end
# 普通のClass の example を呼ぶ
def self.call_class_method
::Book.example
end
def self.example
p 'Module'
end
end
end
Example::Book.call_module_method
Example::Book.call_class_method
Book.example
::Book.example
::Book.example
"Module"
"Class"
"Module"
"Class"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment