Skip to content

Instantly share code, notes, and snippets.

@serinuntius
Last active February 19, 2016 01:59
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 serinuntius/577723bd4f280790e726 to your computer and use it in GitHub Desktop.
Save serinuntius/577723bd4f280790e726 to your computer and use it in GitHub Desktop.
class Person
def initialize(math,english)
#インスタンス変数に代入
@math = math
@english = english
end
#外からアクセスできるように(これをしないと、taro.mathとかで呼び出せない)
attr_accessor :math, :english
end
taro = Person.new(90,80)
takashi = Person.new(70,90)
hanako = Person.new(50,30)
#インスタンス変数を呼び出している
puts taro.math - takashi.math
puts taro.english - takashi.english
puts hanako.english - takashi.english
=begin
<これの面倒なところ>
人数が増えると18〜20行目のように繰り返し書かないとだめ。
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment