Skip to content

Instantly share code, notes, and snippets.

@gouf
Last active August 29, 2015 13:57
Show Gist options
  • Save gouf/9478584 to your computer and use it in GitHub Desktop.
Save gouf/9478584 to your computer and use it in GitHub Desktop.
モジュールとインスタンス変数について
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
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