LoginSignup
0
0

More than 5 years have passed since last update.

Ruby2日目

Last updated at Posted at 2019-01-22

本日学んだこと。

class Robot
  def initialize(name) # initialize、インスタンス化したときに初期化
    @name = name
    @x = @y = 0 # @はインスタンス変数です。
  end

  def move(x, y)
    @x += x
    @y += y
  end

  def to_s
    "#{@name},#{@x},#{@y}"
  end
end

robo1 = Robot.new("仮面ライダー1号") # @nameに自動的にinitializeにより代入
robo2 = Robot.new("ソフトウェアー1号")

robo2.move(10,300) # @x,@yに代入される

puts robo1
puts robo2

筋トレのWebサイトを作成したいです。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0