Class variable

1
2
3
4
5
class Network
def self.get(url, options)
@@result = :test_result
end
end

Instance variable

1
2
3
4
5
class Network
def self.get(url, options)
@result = :test_result
end
end

Temporary attribute on ApplicationRecord

1
2
3
class Tester < ApplicationRecord
attr_accessor :name # for read and write
end

Method nameing

1
2
3
4
5
def available?
end
def update!
end

Class method

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class User
def self.validate!
end
end
class User
class << self
def validate!
end
end
end
def User.validate!
end
User.validate!

Rewrite

1
2
3
4
5
6
7
8
class SubAccount < ApplicationRecord
attr_reader :password # provide instance variable with getter only
def password=(val)
self.password_digest = Digest::SHA1.hexdigest(val)
@password = val
end
end