Ruby

Versions

Debugging

https://github.com/ruby/debug

Gemfile:

gem "debug", ">= 1.0.0"

Application or test code:

debugger

Disabling Docs

~/.gemrc

gem: --no-document

Creating a Standalone Ruby Project

$ mkdir my-project
$ cd my-project
$ git init .
$ npx gitignore ruby
$ bundle init

To create a gem see Ruby Gems

Dates and Times

https://stackoverflow.com/questions/1261329/difference-between-datetime-and-time-in-ruby

Time.now
Time.parse('...')

Info on time zones on Rails

Aliasing

Delegation

Shortcuts

Heredocs

Regexes

/cat/ =~ ​"dog and cat"​ ​# => 8
​"dog and cat"​ =~ /cat/ ​# => 8​
new_str = str.sub(/Cat/, ​"Gerbil"​) # one
new_str2 = str.gsub(/a/, ​"*"​) # global

match_data = /cat/.match("dog and cat")

Ruby Version Features

Modules

# safest to nest modules every time you reference them

# best
module A
  class B
  end
end

# riskier
class A::B
end