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
7 answers

Equivalent of “pass” in Ruby

In python there is a pass keyword for defining an empty function, condition, loop, ... Is there something similar for Ruby? Python Example: def some_function(): # do nothing pass
user1251007
  • 15,891
  • 14
  • 50
  • 76
60
votes
4 answers

Ruby CSV - get current line/row number

I'm trying to work out how to get the current line/row number from Ruby CSV. This is my code: options = {:encoding => 'UTF-8', :skip_blanks => true} CSV.foreach("data.csv", options, ) do |row, i| puts i end But this doesn't seem to work as…
user1513388
  • 7,165
  • 14
  • 69
  • 111
60
votes
5 answers

Mountain Lion rvm install 1.8.7 x11 error

After update to Mountain Lion, I tried install 1.8.7, and I got error. X11 file not found, I installed Xquarkz, but nothing changed. Whats wrong? Fail to find [tclConfig.sh, tkConfig.sh] Use MacOS X Frameworks. Find Tcl/Tk libraries. Make…
user1344853
  • 689
  • 1
  • 7
  • 8
60
votes
5 answers

In Ruby, what's the relationship between 'new' and 'initialize'? How to return nil while initializing?

What I want is: obj = Foo.new(0) # => nil or false This doesn't work: class Foo def initialize(val) return nil if val == 0 end end I know in C/C++/Java/C#, we cant return a value in a constructor. But I'm wondering whether it is possible…
Chris Xue
  • 2,317
  • 1
  • 25
  • 21
59
votes
2 answers

Ruby - How to get the last two values in an array?

numbers = [1, 2, 3, 4, 5, 6, 7, 8] numbers.last # => 8 I need to grab the last two records. So far I've tried this: numbers.last - 1 # throws a `NoMethodError`
gotnull
  • 26,454
  • 22
  • 137
  • 203
59
votes
1 answer

Create an ActiveRecord database table with no :id column?

Is it possible for me to create and use a database table that contains no :id column in ActiveRecord, Ruby on Rails. I don't merely want to ignore the id column, but I wish it to be absolutely non-existent. Table Example :key_column …
Stefan
  • 9,289
  • 7
  • 38
  • 46
59
votes
3 answers

Checking if a variable is defined in SASS

AS the title says I am trying to check whether a variable is defined in SASS. (I am using compass if that makes any different difference) I've found the Ruby equivalent which is: defined? foo Gave that a shot in the dark but it just gave me the…
locrizak
  • 12,192
  • 12
  • 60
  • 80
59
votes
9 answers

How to create a deep copy of an object in Ruby?

I did some searching found some different methods and posts about creating a deep copy operator. Is there a quick and easy (built-in) way to deep copy objects in Ruby? The fields are not arrays or hashes. Working in Ruby 1.9.2.
B Seven
  • 44,484
  • 66
  • 240
  • 385
59
votes
6 answers

God vs. Monit for process monitoring

Which one to use for process monitoring and why?
Milan Novota
  • 15,506
  • 7
  • 54
  • 62
59
votes
1 answer

Outputting errors in a rescue (Ruby/Rails)

Just a quick question. I cant find it in the documentation. If I use a standard begin ... rescue, how do I print all the errors or stack trace into the rescue? e.g.: begin do x rescue puts errors end Any ideas?
overtone
  • 1,063
  • 3
  • 16
  • 23
59
votes
7 answers

after_commit for an attribute

I am using an after_commit in my application. I would like it to trigger only when a particular field is updated in my model. Anyone know how to do that?
alik
  • 3,820
  • 9
  • 41
  • 55
59
votes
5 answers

Radio buttons on Rails

Similar to this question: Checkboxes on Rails What's the correct way of making radio buttons that are related to a certain question in Ruby on Rails? At the moment I have:

<%=…
alamodey
  • 14,320
  • 24
  • 86
  • 112
59
votes
4 answers

How do you loop through a multiline string in Ruby?

Pretty simple question from a first-time Ruby programmer. How do you loop through a slab of text in Ruby? Everytime a newline is met, I want to re-start the inner-loop. def parse(input) ... end
alamodey
  • 14,320
  • 24
  • 86
  • 112
59
votes
1 answer

Understanding ruby-prof output

I ran ruby-profiler on one of my programs. I'm trying to figure out what each fields mean. I'm guessing everything is CPU time (and not wall clock time), which is fantastic. I want to understand what the "---" stands for. Is there some sort of stack…
Prasanna
  • 735
  • 7
  • 10
59
votes
6 answers

Skip over iteration in Enumerable#collect

(1..4).collect do |x| next if x == 3 x + 1 end # => [2, 3, nil, 5] # desired => [2, 3, 5] If the condition for next is met, collect puts nil in the array, whereas what I'm trying to do is put no element in the returned array if the…
Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214