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

Overriding a module method from a gem in Rails

The will_paginate gem is broken on my version of Oracle. The default paginate_by_sql method in the WillPaginate module is inserting an extra 'AS' into a query and causing it to fail. The code itself is easily fixed, but I'm not sure of the best way…
Dave Smylie
  • 2,663
  • 3
  • 25
  • 32
60
votes
8 answers

Good Cucumber examples in the wild?

I've tried Cucumber for a few projects a couple of years ago and am looking to give it another go. I don't really need another "Beginning Cucumber" article. Instead, I'd like to see some actual uses in the wild—one's that other Cucumber users would…
AndrewO
  • 1,590
  • 1
  • 17
  • 24
60
votes
5 answers

STI, one controller

I'm new to rails and I'm kind of stuck with this design problem, that might be easy to solve, but I don't get anywhere: I have two different kinds of advertisements: highlights and bargains. Both of them have the same attributes: title, description…
Pizzicato
  • 1,473
  • 1
  • 16
  • 32
60
votes
1 answer

Double colons before class names in Ruby?

I have seen a lot usage of double colons in Rails before class names. For example: require ::File.expand_path('../config/environment', __FILE__) I know what Module::Class::Constant means, but ::Class ?
omtr
  • 869
  • 2
  • 7
  • 7
60
votes
9 answers

Ruby equivalent of Python's "dir"?

In Python we can "dir" a module, like this: >>> import re >>> dir(re) And it lists all functions in the module. Is there a similar way to do this in Ruby?
HelpMe
60
votes
4 answers

What is the difference between `try` and `&.` (safe navigation operator) in Ruby

Here is my code: class Order < Grape::Entity expose :id { |order, options| order.id.obfuscate } expose :time_left_to_review do |order, options| byebug order&.time_left_to_review # ERROR end expose :created_at { |order, options|…
Adrien
  • 2,088
  • 1
  • 18
  • 35
60
votes
6 answers

Getting a substring in Ruby by x number of chars

I'm trying to produce some Ruby code that will take a string and return a new one, with a number x number of characters removed from its end - these can be actual letters, numbers, spaces etc. Ex: given the following string a_string = "a1wer4zx" I…
wotaskd
  • 925
  • 1
  • 10
  • 15
60
votes
2 answers

'-%>' (minus sign) at the end of a ERb sequence

What's the point of using '-' (minus sign) at the end of a ERb sequence? Example: <% 3.times do -%> FooBar
<% end -%> Sometext Regardless of whether I use '-' or not, a browser renders the same output. Thanks, Aplha.
Alpha Sisyphus
  • 1,508
  • 3
  • 19
  • 33
60
votes
2 answers

When to use node.js vs sinatra vs rails?

What are the best uses for these 3 languages/frameworks? Is it useful to mix all of them (or 2)?
donald
  • 23,587
  • 42
  • 142
  • 223
60
votes
5 answers

How to get all class names in a namespace in Ruby?

I have a module Foo, that it is the namespace for many classes like Foo::Bar, Foo::Baz and so on. Is there an way to return all class names namespaced by Foo?
Sławosz
  • 11,187
  • 15
  • 73
  • 106
60
votes
2 answers

Undefined instance method "respond_to" in Rails 5 API Controller

In rails 5 created with --api I have an error NoMethodError (undefined method `respond_to' for # Did you mean? respond_to?): However, in the documentation for rails 4.2 it says…
Incerteza
  • 32,326
  • 47
  • 154
  • 261
60
votes
6 answers

Rails Console find users by array of ids

So I have an array of user ids. Is there a way in rails console to query all of these user's with the array something like ids = [1, 2, 3, 4] users = User.find(ids) and have it return all 4 users?
Seth
  • 10,198
  • 10
  • 45
  • 68
60
votes
4 answers

Finding the cause of a memory leak in Ruby

I've discovered a memory leak in my Rails code - that is to say, I've found what code leaks but not why it leaks. I've reduced it down to a test case that doesn't require Rails: require 'csspool' require 'ruby-mass' def report puts 'Memory ' +…
jb_314
  • 1,373
  • 2
  • 17
  • 28
60
votes
2 answers

How to see the dependency tree just from Gemfile?

I am getting the following error when doing bundle install Make sure that `gem install couchbase -v '1.3.3'` succeeds before bundling. Now, i have not included this gem in the Gemfile, so it's coming from some dependency. How can i figure out which…
Mohit Verma
  • 2,019
  • 7
  • 25
  • 33
60
votes
17 answers

Ruby and "You must recompile Ruby with OpenSSL support or change the sources in your Gemfile"

Using rvm I upgraded my ruby to 1.9.3-p392, also added 2.0.0, anytime I try to use this version when I run my bundle command I get this error. Could not load OpenSSL. You must recompile Ruby with OpenSSL support or change the sources in your Gemfile…
covard
  • 1,667
  • 2
  • 18
  • 33