0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

rubyの公開レベル public

Posted at

クラスメソッドはクラスの外部からでも自由に呼び出せるメソッドです。initializeメソッド以外のインスタンスメソッドはデフォルトでpublicメソッドになります。

irb(main):001* class User
irb(main):002*   def hello
irb(main):003*     'hello'
irb(main):004*   end
irb(main):005> end
=> :hello
irb(main):006> user = User.new
=> #<User:0x000000010be60030>
irb(main):007> user.hello
=> "hello"

railsで確かめてみる

> User.initialize
:1:in `<main>': private method `initialize called for User:Class (NoMethodError)
garden(dev)> User.all
  User Load 
....
> User.adafa
:3:in `<main>': undefined method `adafa' for User:Class (NoMethodError)
  • initializeメソッドはprivate methodメソッドだ
  • 意味不明なメソッドを書いてみるとundefined methodと出る

感想

確かめてみてよかった。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?