LoginSignup
0
0

More than 1 year has passed since last update.

【Ruby】オブジェクト の クラス と メソッド の 調べ方

Posted at

目的

  • プログラミングで重要な、分からないことを調べるための手段を学ぶ。

ポイント

  • classメソッドを使う。
  • pry で ls を使う。
  • --grep でメソッドを絞り込む。

書き方の例


オブジェクトのクラスを調べる
"".class

クラスの持つメソッドを表示する
ls "" 
ls "" --grep upcase

~実際の表示〜

  • => String

  • String#methods:
    % delete length squeeze など

  • String#methods: upcase upcase!

注意するポイント

  • lsコマンドは、pry でしか使用出来ない。

具体的な例

"HELLO WORLD"のクラスを調べる。
さらに、そのクラスが持つメソッドを使って小文字にする。

~サンプルコード~

"HELLO WORLD".class

ls "HELLP WORLD" --grep downcase

puts "HELLO WORLD".downcase

~プレビュー画面~

  • => String

  • String#methods: downcase downcase!

  • hello world

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