Dynamically typed open-source programming language known for its simplicity, flexibility, and focus on developer happiness.
Not my main language but it's an easy language to pick up so I've written a few bits and pieces over the years eg. check_puppet.rb.
- Popularity Over the Years
- Poignant Guide to Ruby
- IRB
- Gem
- rbenv
- RVM - Ruby Version Manager
- Code
- Linting
- JRuby
- Ruby IDEs
- Meme
IMO was at peak popularity in the late 2000s when Puppet was the big thing (Puppet was written in Ruby) and was the first widely used configuration language (CFengine wasn't as widely used).
Update: a quick Google found this article showing Ruby actually peaked in the mid 2000s rather than the late 2000s. I probably should have made more notes here at that time...
A popular source for learning Ruby.
http://www.rubyinside.com/media/poignant-guide.pdf
Interactive Ruby interpreter.
(if you need to install the irb Gem see next section)
Start the irb interactive ruby interpreter:
irbJRuby interactive Ruby interpreter.
Start the jirb interactive ruby interpreter:
jirbGUI irb using swing:
jruby -S jirb_swingjava_import java.lang.System
version = System.getProperties["java.runtime.version"]gem install "$name"Install the mdl gem for markdown linting (used heavily to check the docs in this repo):
gem install mdlRun mdl to check an .md file:
mdl README.mddotenv- load.envor.envrcfilesirb- Interactive Ruby interpretermdl- Markdown lintlolcat- turns text into rainbow coloursgitlab- GitLab CLIfastlane- see Fastlane docjgrephttpartygistkramdown
gem listConfigure gem command to install gems to user writable $HOME/.gem/ruby/<version>/gems/ directory:
In $HOME/.gemrc:
gem: --user-install
gem install then installs to ~/.gem/ruby/<version>/gems.
Then make sure to add $HOME/.gem/ruby/<version>/bin to $PATH environment to be able to run commands installed by
gems:
gem envRuns server on http://localhost:8808 to show installed gems:
gem servergem install ruby-debuggem install cheatgem install --source http://serverInstalls to ~/rbenv (RBENV_ROOT):
brew install rbenvAdds to ~/.bash_profile:
rbenv initOpen a new login shell:
bash -lor source:
source ~/.bash_profileList installed ruby versions:
rbenv versions* system
List latest stable versions:
rbenv install -lList all local versions:
rbenv install -LInstall a Ruby version:
rbenv install 3.4.1Set the local Ruby version for this directory (creates a .ruby-version file):
rbenv local 3.4.1Show the local configured version:
rbenv localUndo the local ruby setting:
rbenv local --unsetSet the global ruby version by setting ~/.rbenv/version:
rbenv global 3.4.1Set the Ruby version in the local shell only with environment variable RBENV_VERSION:
rbenv shell 3.4.1which irb/Users/hari/.rbenv/shims/irb
rbenv which irb/Users/hari/.rbenv/versions/3.4.1/bin/irb
Check your gem is using the rbenv ruby version:
gem env home/Users/hari/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0
rbenv which gem/Users/hari/.rbenv/versions/3.4.1/bin/gem
Then gem install as usual:
gem install bundlerrbenv versionsrbenv versions
system
* 3.4.1 (set by /Users/hari/github/.../.ruby-version)
rbenv versionrbenv version
3.4.1 (set by /Users/hari/github/.../.ruby-version)
Installs multiple Ruby environments, interpreters and gem commands under
Like VirtualEnv in Python - multiple ruby environments, interpreters and gems
Install GPG Keys:
gpg2 --keyserver keyserver.ubuntu.com \
--recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \
7D2BAF1CF37B13E2069D6956105BD0E739499BDBOn Mac, had to do this instead:
gpg --keyserver hkps://keys.openpgp.org \
--recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \
7D2BAF1CF37B13E2069D6956105BD0E739499BDBPrompts to import GPG keys if you skipped the step above:
curl -sSL https://get.rvm.io | bash -s stableor with Ruby-on-Rail (compiles, takes ages):
curl -sSL https://get.rvm.io | bash -s stable --railsYou will likely get a warning to remove the user gem setting from $HOME/.gemrc as it'll clash with RVM:
In $HOME/.gemrc, remove:
gem: --user-install
See available interpreters:
rvm list knownInstall a recent Ruby interpreter:
rvm install rubyFurther help:
rvm help| Code | Description |
|---|---|
foo |
local variable (default: NameError: undefined local variable exception) |
$foo |
global variable (default: nil) |
@foo |
instance variable (default: nil) |
@@foo |
class variable (default: NameError exception) |
^[A-Z]... |
constant (default: NameError exception) |
puts object.inspectobject.to_yamlPath to code modules:
$LOAD_PATH
gem install rubocoprubocopAuto-correct the file(s) at your own peril:
(make sure you git commit before running this to see the changes / revert)
rubocop -awill annoyingly space all:
#comment_out_codelines to
# comment_out_codebut where they are opening blocks it won't indent the block contents to stay aligned by 2 space indents:
# lane :build do |options|
# puts "Building version #{options[:version]}"
# endRun Ruby on the Java JVM with full access to Java libraries.
See also Jython.
Personally, I much prefer Groovy.
Use Java library jar:
require '/path/to/my.jar'Not needed in jirb (JRuby's interactive interpreter):
require 'java'import java.lang.SystemNewer safer way to import from Java:
java_import java.lang.Systemversion = System.getProperties["java.runtime.version"]this does equiv of: import org.xxx.yyy and includes *:
include_package "org.xxx.yyy"JIT for Ruby
http://rubystuff.org/ludicrous/
JIT for Ruby
Experimental last I checked and performance roughly on par with YARV (Yet Another Ruby VM bytecode interpreter) which has since been merged into official Ruby 1.9 interpreter 2007.
https://www.jetbrains.com/ruby/
Ruby-specific IDE by Jebrains, based off IntelliJ IDEA.
Unfortuntely, this is proprietary paid for only and doesn't have a free version like PyCharm or main IntelliJ.
VS Code, Sublime or Gleany.
See Editors & IDEs page.
Ported from private Knowledge Base page 2012+
