
We sometimes want to develop global function which is common in software. For example, it is a function that notifies users of errors. In that case, we can use window object.
import notify from 'path/to/notify'window.notify = notifyfunction a () {
notify()
}
function b () {
notify()
}
My LinkedIn account is below! Please contact me!
https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

Basically, while writing ruby codes, I avoid using inheritance because inheritance sometimes produce unnecessary tight couplings.
Example
class Vehicle
def start_engine
end def stop_engine
end
end
class Car < Vehicle
def drive
start_engine
stop_engine
end
end
In this case, Car class knows about the codes of Vehicle class. If we create objects that don’t use an engine, it will necessary to take much time to change the codes.
Solution
We should use compositions. In other words, we should define Engine object.
class Car
def initialize
@engine = Engine.new
end def drive
@engine.start
@engine.stop
end
end class Engine
def start
end def stop
end
end
In this case, Engine class was separated from Car class. Moreover, it has become easy to make new objects that don’t use an engine.
My LinkedIn account is below! Please contact me!
https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

Basically, “bundle exec” command precedes rails commands. My subordinate asked me about the necessity of this command. I’m going to write it down here.
Rails has gemfile.lock file that solves dependencies among gems. When we use bundle exec command, gemfile.lock file is referred to. Instead of that, if we don’t use bundle exec command, gemfile.lock file isn’t referred to. As a result, a gem might not work properly.
My LinkedIn account is below! Please contact me!
https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

class A
class << self
LOGO_PATH = 'api/path'
LOGO_WIDTH = 150
end
end
What should we do if we want to get LOGO_PATH and LOGO_WIDTH in other places?
The solution is
A.singleton_class::LOGO_PATH => 'api/path'
A.singleton_class::LOGO_WIDTH => 150
The reference is below.
My LinkedIn account is below! Please contact me!
https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

We sometimes have to read library codes for curiosity or bug fixes. However, there are some techniques needed, so I’ll write them down here.
Set up path for installing gems
bundle config set path ‘vendor/bundle’ —- local
Codes of library become visible in our projects and it has become possible to insert pry codes into libraries.
Find where methods are defined
class Book
def read
end
end> Book.new.method(:read).source_location
=> ['book.rb', 2]
Use debuggers
・binding.irb
・binding.pry
・byebug
Find a caller
・puts caller
class BooksController < ApplicationController
def index
puts caller
end
end
# caller is default in Ruby
・backtrace(this is in byebug)
That’s all! Make debugging more effective by using techniques above.