Created
February 19, 2016 02:07
-
-
Save serinuntius/8762fa570554a4a04688 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 | |
#クラスの外でメソッドを作る | |
def fight_with_math(a,b) | |
puts a.math - b.math | |
end | |
def fight_with_english(a,b) | |
puts a.english - b.english | |
end | |
#インスタンス生成 | |
taro = Person.new(90,80) | |
takashi = Person.new(70,90) | |
hanako = Person.new(50,50) | |
#メソッド呼び出し | |
fight_with_english(taro,takashi) | |
fight_with_math(hanako,takashi) | |
fight_with_math(hanako,taro) | |
=begin | |
<いいところ> | |
puts の書く回数が減った | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment