Skip to content

Instantly share code, notes, and snippets.

@sacarlson
Created September 13, 2015 20:11
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 sacarlson/25b99990338f1d04ce5d to your computer and use it in GitHub Desktop.
Save sacarlson/25b99990338f1d04ce5d to your computer and use it in GitHub Desktop.
module Module2
class Class2
include Module2
end
def version
return "0.1.0"
end
end
include Module2
# if this function name is version instead of version2 we get
#test_module.rb:28:in `<main>': private method `version' called for Module2:Module (NoMethodError)
def version
return "0.2.0"
end
x = Module2::Class2.new
# this puts "#{Module2.version}" won't work without include
puts "#{x.version}"
puts "#{Module2::Class2.new.version}"
# can't do puts "#{Module2.version}" when version not renamed to version2
#puts "#{Module2.version}"
puts "#{version}"
#result
#0.1.0
#0.1.0
#0.2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment