Created
March 23, 2017 10:05
-
-
Save sortega/0b266fe7e6ea3c68b0472f3a8135e4c6 to your computer and use it in GitHub Desktop.
Static methods and modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ruby statics.rb | |
4 | |
statics.rb:12:in `<main>': undefined method `non_static' for Foo:Module (NoMethodError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
def non_static(x) | |
x * x | |
end | |
def self.static(x) | |
x * x | |
end | |
end | |
puts Foo.static(2) | |
puts Foo.non_static(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is how it's done: http://blog.bigbinary.com/2012/06/28/extend-self-in-ruby.html