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
65
votes
3 answers

RSpec: How could I use the array include matcher in the expect syntax

I use new RSpec syntax (expect instead of should) and I'd like to test if an array includes elements of another array. In the old syntax it would be: array1.should include(array2) In the new syntax I tried to write: expect(array1).to…
mrzasa
  • 22,895
  • 11
  • 56
  • 94
65
votes
2 answers

How to undefine class in Ruby?

Undefining a method in Ruby is pretty simple, I can just use undef METHOD_NAME. Is there anything similar for a class? I am on MRI 1.9.2. I have to undefine an ActiveRecord Model, run two lines of code, and restore the model back to its original…
Bhushan Lodha
  • 6,824
  • 7
  • 62
  • 100
65
votes
3 answers

Programmatically get the number of jobs in a Resque queue

I am interested in setting up a monitoring service that will page me whenever there are too many jobs in the Resque queue (I have about 6 queues, I'll have different numbers for each queue). I also want to setup a very similar monitoring service…
randombits
  • 47,058
  • 76
  • 251
  • 433
65
votes
6 answers

Ruby run shell command in a specific directory

I know how to run a shell command in Ruby like: %x[#{cmd}] But, how do I specify a directory to run this command? Is there a similar way of shelling out, similar to subprocess.Popen in Python: subprocess.Popen(r'c:\mytool\tool.exe',…
icn
  • 17,126
  • 39
  • 105
  • 141
64
votes
3 answers

Relative path to your project directory

In my Ruby project I am using a mess of things like moving and editing files on several remote boxes and I really need something like a relative path to my root project directory. I have many processing folders which are used in many methods. Right…
qwebek
  • 949
  • 2
  • 8
  • 15
64
votes
5 answers

Checking character length in ruby

I got stuck in another situation: our users enter a text to be stored in a variable. The condition for that text is it can be allowed to enter only 25 characters, Now I have to write a regular expression which will check the condition, kindly help…
Vijay Sali
  • 1,030
  • 2
  • 14
  • 32
64
votes
3 answers

Role does not exist and unable to create database when using PostgreSQL

I am using Heroku for my application and it requires PostgreSQL but you can still use SQLite3 for development. Since Heroku strongly advised against having 2 different databases I decided to change to PostgreSQL for development. I installed the gem…
LearningRoR
  • 26,582
  • 22
  • 85
  • 150
64
votes
3 answers

Understanding Ruby's load paths

I'm a little confused about why my project can't load the files it needs, it's a really simple project tree: processor/ bin/ lib/ processor.rb processor/ mapper.rb reducer.rb and my processor.rb file looks like require…
JP Silvashy
  • 46,977
  • 48
  • 149
  • 227
64
votes
4 answers

Rails 3: yield/content_for with some default value?

Is there any way to detect if #content_for was actually applied to a yield scope in Rails? A classic example being something like: <%= yield :page_title %> If a template doesn't set that with <% content_for :page_title, "Something…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
64
votes
5 answers

If I have a hash in Ruby on Rails, is there a way to make it indifferent access?

If I already have a hash, can I make it so that h[:foo] h['foo'] are the same? (is this called indifferent access?) The details: I loaded this hash using the following in initializers but probably shouldn't make a difference: SETTINGS =…
Sarah W
  • 889
  • 1
  • 6
  • 10
64
votes
3 answers

How can I run a command five times using Ruby?

How can I run a command five times in a row? For example: 5 * send_sms_to("xxx");
donald
  • 23,587
  • 42
  • 142
  • 223
64
votes
13 answers

Lisp and Erlang Atoms, Ruby and Scheme Symbols. How useful are they?

How useful is the feature of having an atom data type in a programming language? A few programming languages have the concept of atom or symbol to represent a constant of sorts. There are a few differences among the languages I have come across…
Muhammad Alkarouri
  • 23,884
  • 19
  • 66
  • 101
64
votes
5 answers

Finding the session id in rails 3

How can I get the current session id in rails 3? I've tried the following with no luck: session[:session_id] session['session_id'] session[:id] session['id'] session.id session.session_id
Austin
  • 3,860
  • 3
  • 23
  • 25
64
votes
4 answers

Rubygems, Bundler and RVM confusion

I read "Relationships between Rubygems, Bundler, and RVM" before asking it again. Well, there are many questions like this, but people who answered say they work with Rubygems, RVM and Bundler, and they have not explained how each of these work in…
Anand
  • 10,310
  • 24
  • 90
  • 135
64
votes
8 answers

Sum the value of array in hash

This is my array [{:amount=>10, :gl_acct_id=>1, :alt_amount=>20}, {:amount=>20, :gl_acct_id=>2 , :alt_amount=>30}] i want result [{:amount => 30}] or {:amount = 30} Any idea?
krunal shah
  • 16,089
  • 25
  • 97
  • 143