LoginSignup
0
0

More than 1 year has passed since last update.

【小ネタ】Ruby で new するたびにクラスインスタンス変数をインクリメントして、インスタンス変数にぶち込む

Last updated at Posted at 2021-08-14
class BankAccount
  @current_account_number = 0

  def self.new(name)
    super(name, @current_account_number += 1)
  end

  attr_accessor :name
  attr_reader :account_number

  def initialize(name, account_number)
    @account_number = account_number
    @name = name
  end
end
0
0
0

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