Last active
February 19, 2016 01:59
-
-
Save serinuntius/577723bd4f280790e726 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
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