Help us understand the problem. What is going on with this article?

ruby:メモ

More than 5 years have passed since last update.

ruby:メモ

コーディング規約

覚えておきたいメソッド

"hello, world".upcase
=> "HELLO, WORLD"
"hello, world".reverse
=> "dlrow, olleh"
"hello, world".methods
=> [:<=>, :==, :===, :eql?, :hash, :casecmp, :+, :*....
object_id(=self.object_id)
=> 17084920
1.+(1)(=1 + 1)
=> 2
object.singleton_methods
=> [:to_s, :inspect, :context, :conf, :irb_quit,...
hello = "hello, world"
hello.class
=> String

クラスとインスタンス

インスタンス変数の定義

class Book
    def author
        @author
    end
    def title
        @title
    end
    def isbn
        @isbn
    end

    def author=(author)
        @author = author
    end
    def title=(title)
        @title = title
    end
    def isbn=(isbn)
        @isbn = isbn
    end
end

↓等価↓

class Book
    attr_accessor :author, :title, :isbn
end

外部ファイルの読み込み

require_relative 'book'
=> true

インスタンス生成

book = Book.new
=> #<Book:0x007fba434564f3>

値の設定

book.author = "jon smith"
=> "jon smith"

値の取得

book.author
=> "jon smith"
rorono
MW級大電力電力取り扱い技術者もどき| 純粋独学エンジニア| C/C++/Python/Ruby/Javascript/PHP/Golang/HTML/CSS/Sass/OpenCV/Git/Docker/jQuery/機械学習/
https://rorono.net/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした