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

How to get only class name without namespace

There is a class like this. module Foo class Bar end end And I want to get the class name of Bar without Foo. bar = Foo::Bar.new bar.class.to_s.match('::(.+)$'){ $1 } I could get the class name by this code, but I don't think this is a best…
ironsand
  • 14,329
  • 17
  • 83
  • 176
66
votes
4 answers

How to redefine a Ruby constant without warning?

I'm running some Ruby code which evals a Ruby file every time its date changes. In the file, I have constant definitions, like Tau = 2 * Pi and, of course, they make the interpreter display the unwanted "already initialized constant" warning every…
Eldritch Conundrum
  • 8,452
  • 6
  • 42
  • 50
66
votes
5 answers

How to use gem to install Rails on Ubuntu

The error message: Building native extensions. This could take a while... ERROR: Error installing rails: ERROR: Failed to build gem native extension. /usr/bin/ruby2.1 -r ./siteconf20150328-1540-hff2f0.rb extconf.rb checking if the C…
Allen
  • 6,745
  • 5
  • 41
  • 59
66
votes
14 answers

no such file to load -- rubygems (LoadError)

I recently installed rails in fedora 12. I'm new to linux as well. Everything works fine on Windows 7. But I'm facing lot of problems in linux. Help please! I've installed all the essentials to my knowledge to get the basic script/server up and…
Vineeth Pradhan
  • 8,201
  • 7
  • 33
  • 34
66
votes
10 answers

How do I add information to an exception message in Ruby?

How do I add information to an exception message without changing its class in ruby? The approach I'm currently using is strings.each_with_index do |string, i| begin do_risky_operation(string) rescue raise $!.class, "Problem with string…
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
66
votes
4 answers

Looking for suggestions for building a secure REST API within Ruby on Rails

I'm getting started on building a REST API for a project I'm working on, and it led me to do a little research as to the best way to build an API using RoR. I find out pretty quickly that by default, models are open to the world and can be called…
Levi Rosol
  • 4,398
  • 6
  • 28
  • 36
66
votes
7 answers

How do I add multiple elements to an array?

I can easily add one element to an existing array: arr = [1] arr << 2 # => [1, 2] How would I add multiple elements to my array? I'd like to do something like arr << [2, 3], but this adds an array to my array #=> [1, [2, 3]]
davegson
  • 8,205
  • 4
  • 51
  • 71
66
votes
3 answers

Ruby: define_method vs. def

As a programming exercise, I've written a Ruby snippet that creates a class, instantiates two objects from that class, monkeypatches one object, and relies on method_missing to monkeypatch the other one. Here's the deal. This works as…
gauth
  • 908
  • 1
  • 7
  • 11
66
votes
5 answers

to_d to always return 2 decimals places in ruby

I'm dealing with currencies and I want to round down the number to 2 decimal places. Even if the number is 500.0, I would like it to be 500.00 to be consistent. When I do "500.00".to_d it converts it to 500.0. Whats a good way of changing this…
ed1t
  • 8,719
  • 17
  • 67
  • 110
66
votes
2 answers

First element of an array with condition

Is there a shorter way to find the first element in an array meeting some conditions than this: my_array[ my_array.index {|x| x.some_test} ]
Balzard
  • 1,246
  • 1
  • 12
  • 17
66
votes
11 answers

How do you find the namespace/module name programmatically in Ruby on Rails?

How do I find the name of the namespace or module 'Foo' in the filter below? class ApplicationController < ActionController::Base def get_module_name @module_name = ??? end end class Foo::BarController < ApplicationController …
Steropes
  • 4,600
  • 2
  • 22
  • 26
66
votes
10 answers

How can we watch the Rails development log?

A member of my team is developing a Rails app on Windows XP. We are finding that when we run the app, either launching it within NetBeans or by opening a console and calling script/server, the Rails development log does not scroll by. There is only…
Ethan
  • 57,819
  • 63
  • 187
  • 237
65
votes
1 answer

Ruby - time.now in UTC

Possible Duplicate: How do I Convert DateTime.now to UTC in Ruby? How do I get current time in Date-time-milliseconds & UTC? Ex. 2012-03-22T18:48:40.873Z I tried - Time.now.utc_offset.to_s Time.now.xs_datetime
Majoris
  • 2,963
  • 6
  • 47
  • 81
65
votes
6 answers

What are the paths that "require" looks up by default?

In Ruby, I have been told that when doing require "some_file" Ruby will look for the file in certain places. I know that it looks for some_file.rb, but where does it look for it by default?
Mark Provan
  • 1,041
  • 2
  • 13
  • 19
65
votes
5 answers

How to sort a string's characters alphabetically?

For Array, there is a pretty sort method to rearrange the sequence of elements. I want to achieve the same results for a String. For example, I have a string str = "String", I want to sort it alphabetically with one simple method to "ginrSt". Is…
steveyang
  • 9,178
  • 8
  • 54
  • 80