Razzi's guide to Ruby
(I’m a ruby beginner)
debug your ruby code
Say you have a method like so:
def rere(soso)
puts soso
end
You can get inside it by adding binding.irb:
def rere(soso)
binding.irb
puts soso
end
Now when you run the method you’ll get a full debugging console:
$ ruby code.rb
From: code.rb @ line 2 :
1: def soso(gogo)
=> 2: binding.irb
3: puts gogo
4: end
5:
6: soso 333
irb(main):001> gogo
=> 333
irb ruby repl
Ruby ships with irb, for interactive ruby. It’s pretty good! It supports tab completion, syntax highlighting, inline documentation, and command history.
$ irb
irb(main):001> Gem.dir
=> "/opt/homebrew/lib/ruby/gems/3.4.0"
It’s especially important that this is included since if you run ruby by itself, it reads from stdin and blocks, which it has to do since you can pipe ruby code to ruby.
$ echo 'puts 1' | ruby
1
Add ruby gems executables to path
Add this line to ~/.profile and reload your profile:
export PATH="$(ruby -e 'puts Gem.dir')/bin:$PATH"
export PATH="$(ruby -e 'puts Gem.user_dir')/bin:$PATH"
There are 2 gem directories: one for things installed with
gem install and one for things installed with gem install --user.