Last active
August 29, 2015 13:57
-
-
Save gouf/9478584 to your computer and use it in GitHub Desktop.
モジュールとインスタンス変数について
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 Greeting | |
def self.hello name | |
@name = name | |
"Hello #{name}" | |
end | |
def self.name | |
@name | |
end | |
end | |
puts Greeting.hello('John') #=> Hello John | |
puts Greeting.name #=> John |
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 Greeting | |
def hello name | |
@name = name | |
"Hello #{name}" | |
end | |
def name | |
@name | |
end | |
end | |
class Hello | |
include Greeting | |
end | |
h = Hello.new | |
puts h.hello('John') #=> Hello John | |
puts h.name #=> John |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment