前提・実現したいこと
アクセサを一括で指定する方法はありますか?
そのクラス内の全てのインスタンス変数を一括で読み取り専用にしたいのですが、できますか?
ご教示お願いします。
試したこと
こちらを参考にしました。
まず、羅列の書き方からできませんでした。
ruby
1class Sample 2 attr_reader :key, :access 3 4 @key = "test1" 5 @access = "test2" 6end
ruby
1class Sample 2 attr_reader :key, :access 3 4 def initialize 5 @key = "test1" 6 @access = "test2" 7 end 8end
回答2件
あなたの回答
tips
プレビュー