Questions tagged [ruby]

Ruby is a multi-platform open-source, dynamic object-oriented interpreted language. The [ruby] tag is for questions related to the Ruby language, including its syntax and its libraries. Ruby on Rails questions should be tagged with [ruby-on-rails].

The tag is for questions related to the Ruby language, including its syntax and its libraries. Questions specifically about the Ruby on Rails framework should be tagged with in addition to . Do not use this to tag ruby used in the Japanese language.

Ruby is an open-source dynamic object-oriented interpreted language that combines concepts from Perl, Smalltalk, and Lisp. It supports multiple programming paradigms including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management; it is, therefore, similar in varying respects to Smalltalk, Python, Perl, Lisp, Dylan, and CLU. Ruby's primary purpose is to "help every programmer in the world to be productive, and to enjoy programming, and to be happy." Ruby focuses on simplicity and productivity.

Ruby was initially conceived on February 24, 1993, by Yukihiro Matsumoto ('Matz') and version 1.0 was released in 1996. Ruby's mindshare spiked around 2005 due to Ruby on Rails, an MVC (Model, View, Controller) framework for building web applications and usage continues to grow as of 2016 with Ruby continuing to find acceptance in the commercial marketplace. The current stable version is 3.2.0 (2022-12-25).

Documentation, Announcements, Issue Tracker

Unofficial Reference

Implementations, Installers

  • Ruby version managers. chruby, rbenv, rvm, pik (Windows)
  • Ruby, the official implementation also known as Matz' Ruby Implementation (MRI), YARV-Ruby. Official Site, GitHub
  • JRuby, an implementation of Ruby on top of Java with access to the JVM
  • Rubinius, an implementation of Ruby supporting native OS threads and a core library written almost entirely in Ruby
  • Ruby Enterprise Edition (not maintained anymore), a branch of MRI Ruby made for efficiency
  • MacRuby, an implementation of Ruby on Apples Objective-C and Cocoa frameworks
  • MagLev an implementation on top of VMWare's GemStone virtual machine
  • IronRuby is an implementation of Ruby on top of Microsoft's .NET CLR/DLR platform
  • Cardinal is an implementation of Ruby for the Parrot Virtual Machine
  • Topaz is an implementation of Ruby written in Python, on top of RPython
  • RubyMotion is an implementation of Ruby to develop native iOS and OS X applications

Gems (Library)

  • Ruby Gems - The Standard Library
  • Ruby Toolbox - Ruby Gems categorization, ranking, and statistics
  • Awesome Ruby - A categorized collection of awesome Ruby libraries, tools, frameworks, and software. The essential Ruby to build modern Apps and Web Apps
  • Bundler - Manage your application's gem dependencies
  • DevKit - A windows toolkit that makes it easy to build and use native C/C++ extensions

Tools

  • repl.it - Online REPL
  • RSpec - A testing tool for Ruby
  • Minitest - A testing tool for Ruby
  • Rubular - A Ruby regular expression tool
  • Pry - REPL and debugger for Ruby
  • Rubocop - A Ruby linter and code formatter

Online Courses

Books

Related Tags


Icon:

ruby icon

228397 questions
635
votes
13 answers

How to remove RVM (Ruby Version Manager) from my system

How can I remove RVM (Ruby Version Manager) from my system?
lucianosousa
  • 8,144
  • 4
  • 21
  • 25
633
votes
32 answers

How to install a gem or update RubyGems if it fails with a permissions error

I'm trying to install a gem using gem install mygem or update RubyGems using gem update --system, and it fails with this error: ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the…
Gaurav
  • 8,227
  • 4
  • 34
  • 55
620
votes
16 answers

How to sum array of numbers in Ruby?

I have an array of integers. For example: array = [123,321,12389] Is there any nice way to get the sum of them? I know, that sum = 0 array.each { |a| sum+=a } would work.
brainfck
  • 9,286
  • 7
  • 28
  • 29
619
votes
7 answers

Begin, Rescue and Ensure in Ruby?

I've recently started programming in Ruby, and I am looking at exception handling. I was wondering if ensure was the Ruby equivalent of finally in C#? Should I have: file = File.open("myFile.txt", "w") begin file << "#{content} \n" rescue …
Lloyd Powell
  • 18,270
  • 17
  • 87
  • 123
607
votes
15 answers

Checking if a variable is defined?

How can I check whether a variable is defined in Ruby? Is there an isset-type method available?
readonly
  • 343,444
  • 107
  • 203
  • 205
591
votes
8 answers

What's the difference between equal?, eql?, ===, and ==?

I am trying to understand the difference between these four methods. I know by default that == calls the method equal? which returns true when both operands refer to exactly the same object. === by default also calls == which calls equal?... okay,…
denniss
  • 17,229
  • 26
  • 92
  • 141
565
votes
18 answers

How do you add an array to another array in Ruby and not end up with a multi-dimensional result?

I tried: somearray = ["some", "thing"] anotherarray = ["another", "thing"] somearray.push(anotherarray.flatten!) I expected ["some", "thing", "another", "thing"] but got ["some", "thing", nil]
ncvncvn
  • 5,683
  • 2
  • 16
  • 4
563
votes
5 answers

Ruby: kind_of? vs. instance_of? vs. is_a?

What is the difference? When should I use which? Why are there so many of them?
Claudiu
  • 224,032
  • 165
  • 485
  • 680
550
votes
17 answers

What does map(&:name) mean in Ruby?

I found this code in a RailsCast: def tag_names @tag_names || tags.map(&:name).join(' ') end What does the (&:name) in map(&:name) mean?
collimarco
  • 34,231
  • 36
  • 108
  • 142
545
votes
5 answers

Why use Ruby's attr_accessor, attr_reader and attr_writer?

Ruby has this handy and convenient way to share instance variables by using keys like attr_accessor :var attr_reader :var attr_writer :var Why would I choose attr_reader or attr_writer if I could simply use attr_accessor? Is there something like…
Saturn
  • 17,888
  • 49
  • 145
  • 271
542
votes
9 answers

Should Gemfile.lock be included in .gitignore?

I'm sort of new to bundler and the files it generates. I have a copy of a git repo from GitHub that is being contributed to by many people so I was surprised to find that bundler created a file that didn't exist in the repo and wasn't in the…
aarona
  • 35,986
  • 41
  • 138
  • 186
537
votes
1 answer

How to Uninstall RVM?

Possible Duplicate: How to remove rvm (ruby version manager) from my system? How can I uninstall (or reinstall) RVM on Ubuntu 9.10? I messed up my current installation.
conbask
  • 9,741
  • 16
  • 57
  • 94
527
votes
33 answers

Error installing mysql2: Failed to build gem native extension

I am having some problems when trying to install mysql2 gem for Rails. When I try to install it by running bundle install or gem install mysql2 it gives me the following error: Error installing mysql2: ERROR: Failed to build gem native…
spacemonkey
  • 19,664
  • 14
  • 42
  • 62
519
votes
11 answers

What is the difference between include and require in Ruby?

My question is similar to "What is the difference between include and extend in Ruby?". What's the difference between require and include in Ruby? If I just want to use the methods from a module in my class, should I require it or include it?
Owen
  • 22,247
  • 13
  • 42
  • 47
516
votes
17 answers

How to reverse a 'rails generate'

I want to delete all the files it created and roll back any changes made, but not necessarily to the database, but more to the config files. I'd like to automatically delete all the resource mappings for the model/controller deleted in the routes.rb…
marcamillion
  • 32,933
  • 55
  • 189
  • 380