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
850
votes
10 answers

Multi-Line Comments in Ruby?

How can I comment multiple lines in Ruby?
Mohit Jain
  • 43,139
  • 57
  • 169
  • 274
826
votes
51 answers

How to generate a random string in Ruby

I'm currently generating an 8-character pseudo-random uppercase string for "A" .. "Z": value = ""; 8.times{value << (65 + rand(25)).chr} but it doesn't look clean, and it can't be passed as an argument since it isn't a single statement. To get a…
Jeff
  • 6,646
  • 5
  • 27
  • 33
825
votes
18 answers

How to get a random number in Ruby

How do I generate a random number between 0 and n?
Mark A. Nicolosi
  • 82,413
  • 11
  • 44
  • 46
823
votes
12 answers

Execute a command line binary with Node.js

I am in the process of porting a CLI library from Ruby over to Node.js. In my code I execute several third party binaries when necessary. I am not sure how best to accomplish this in Node. Here's an example in Ruby where I call PrinceXML to convert…
Dave Thompson
  • 8,453
  • 3
  • 16
  • 11
750
votes
8 answers

How to check if a specific key is present in a hash or not?

I want to check whether the "user" key is present or not in the session hash. How can I do this? Note that I don't want to check whether the key's value is nil or not. I just want to check whether the "user" key is present.
Mohit Jain
  • 43,139
  • 57
  • 169
  • 274
747
votes
8 answers

Equivalent of "continue" in Ruby

In C and many other languages, there is a continue keyword that, when used inside of a loop, jumps to the next iteration of the loop. Is there any equivalent of this continue keyword in Ruby?
Mark Szymanski
  • 56,590
  • 24
  • 70
  • 87
746
votes
20 answers

How to "pretty" format JSON output in Ruby on Rails

I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. Right now, I call to_json and my JSON is all on one line. At times this can be difficult to see if there is a problem in the JSON output stream. Is there way to…
JP Richardson
  • 38,609
  • 36
  • 119
  • 151
722
votes
24 answers

How to drop columns using Rails migration

What's the syntax for dropping a database table column through a Rails migration?
Ethan
  • 9,558
  • 5
  • 27
  • 24
715
votes
6 answers

Difference between rake db:migrate db:reset and db:schema:load

The difference between rake db:migrate and rake db:reset is pretty clear to me. The thing which I don't understand is how rake db:schema:load is different from the former two. Just to be sure that I am on the same page: rake db:migrate - Runs the…
Gaurav Agarwal
  • 14,664
  • 4
  • 29
  • 41
673
votes
18 answers

How to remove a key from Hash and get the remaining hash in Ruby/Rails?

To add a new pair to Hash I do: {:a => 1, :b => 2}.merge!({:c => 3}) #=> {:a => 1, :b => 2, :c => 3} Is there a similar way to delete a key from Hash ? This works: {:a => 1, :b => 2}.reject! { |k| k == :a } #=> {:b => 2} but I would expect to…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
660
votes
27 answers

Ruby function to remove all white spaces?

What is the Ruby function to remove all white spaces? I'm looking for something kind of like PHP's trim()?
gpwu
  • 6,957
  • 3
  • 17
  • 9
658
votes
7 answers

How to write to file in Ruby?

I need to read the data out of database and then save it in a text file. How can I do that in Ruby? Is there any file management system in Ruby?
ohana
  • 6,601
  • 2
  • 17
  • 5
653
votes
12 answers

Why are exclamation marks used in Ruby methods?

In Ruby some methods have a question mark (?) that ask a question like include? that ask if the object in question is included, this then returns a true/false. But why do some methods have exclamation marks (!) where others don't? What does it mean?
Lennie
  • 10,605
  • 5
  • 22
  • 13
651
votes
6 answers

How to match all occurrences of a regular expression in Ruby

Is there a quick way to find every match of a regular expression in Ruby? I've looked through the Regex object in the Ruby STL and searched on Google to no avail.
Chris Bunch
  • 87,773
  • 37
  • 126
  • 127
644
votes
7 answers

How do I pick randomly from an array?

I want to know if there is a much cleaner way of doing this. Basically, I want to pick a random element from an array of variable length. Normally, I would do it like this: myArray = ["stuff", "widget", "ruby", "goodies", "java", "emerald", "etc"…
Paul Hoffer
  • 12,606
  • 6
  • 28
  • 37