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
68
votes
1 answer

RSpec allow/expect vs just expect/and_return

In RSpec, specifically version >= 3, is there any difference between: Using allow to set up message expectations with parameters that return test doubles, and then using expect to make an assertion on the returned test doubles Just using expect to…
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
68
votes
6 answers

How to elegantly symbolize_keys for a 'nested' hash

Consider the following code: hash1 = {"one" => 1, "two" => 2, "three" => 3} hash2 = hash1.reduce({}){ |h, (k,v)| h.merge(k => hash1) } hash3 = hash2.reduce({}){ |h, (k,v)| h.merge(k => hash2) } hash4 = hash3.reduce({}){ |h, (k,v)| h.merge(k…
SHS
  • 7,651
  • 3
  • 18
  • 28
68
votes
2 answers

How do I write a complex multi-line if condition in Ruby?

How do I write this multi-line, complex condition if statement in Ruby? if ( (aa != nil && self.prop1 == aa.decrypt) || (bb != nil && self.prop2 == bb.decrypt) ) && (self.id.nil? || self.id != id) return true end I'm getting…
Chloe
  • 25,162
  • 40
  • 190
  • 357
68
votes
6 answers

Calling method in parent class from subclass methods in Ruby

I've used super to initialize parent class but I cannot see any way of calling parent class from subclass methods. I know PHP and other languages do have this feature but cannot find a good way to do this in Ruby. What would one do in this…
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168
68
votes
8 answers

"rmagick" gem installation issue

I am having issue while trying to install "rmagick" gem on centos. Following is the output I am having. Can anyone please help me identifying what package I am missing? I have installed all mentioned another stack-overflow thread: RMagick install…
Rana
  • 5,912
  • 12
  • 58
  • 91
68
votes
3 answers

How to organize minitest/unit tests?

After using RSpec for several projects, I'm giving minitest/unit a go. I'm liking it so far, but I miss using describe/context blocks to group my tests/specs in a logical way. I know minitest/spec provides this functionality, but I like that…
Doug Johnston
  • 855
  • 1
  • 7
  • 13
68
votes
9 answers

Convert CSV file into array of hashes

I have a csv file, some hockey stats, for example: 09.09.2008,1,HC Vitkovice Steel,BK Mlada Boleslav,1:0 (PP) 09.09.2008,1,HC Lasselsberger Plzen,RI OKNA ZLIN,6:2 09.09.2008,1,HC Litvinov,HC Sparta Praha,3:5 I want to save them in an array of…
Mythago
  • 921
  • 2
  • 9
  • 16
68
votes
5 answers

Ruby deleting directories

I'm trying to delete a non-empty directory in Ruby and no matter which way I go about it it refuses to work. I have tried using FileUtils, system calls, recursively going into the given directory and deleting everything, but always seem to end up…
Ced
  • 1,117
  • 1
  • 8
  • 16
68
votes
4 answers

How do you use global variables or constant values in Ruby?

I have a program that looks like: $offset = Point.new(100, 200); def draw(point) pointNew = $offset + point; drawAbsolute(point) end draw(Point.new(3, 4)); the use of $offset seems a bit weird. In C, if I define something outside of any…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
68
votes
10 answers

Rails: An elegant way to display a message when there are no elements in database

I realized that I'm writing a lot of code similar to this one: <% unless @messages.blank? %> <% @messages.each do |message| %> <%# code or partial to display the message %> <% end %> <% else %> You have no messages. <% end %> Is there…
Jakub Troszok
  • 99,267
  • 11
  • 41
  • 53
67
votes
9 answers

Ruby: merge nested hash

I would like to merge a nested hash. a = {:book=> [{:title=>"Hamlet", :author=>"William Shakespeare" }]} b = {:book=> [{:title=>"Pride and Prejudice", :author=>"Jane Austen" }]} I would like the merge to…
user1223862
  • 1,193
  • 2
  • 9
  • 10
67
votes
10 answers

Rails 3. How to add a helper that ActiveAdmin will use?

I'm creating a helper to be used by Formtastic but I get the undefined local variable or method error. I don't know where to put it so it can work. I already tried in the application_helper.rb and in app/helpers/active_admin/view_helpers.rb
leonel
  • 10,106
  • 21
  • 85
  • 129
67
votes
7 answers

How to check if a variable is a number or a string?

How to check if a variable is a number or a string in Ruby?
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
67
votes
35 answers

Why learn Perl, Python, Ruby if the company is using C++, C# or Java as the application language?

I wonder why would a C++, C#, Java developer want to learn a dynamic language? Assuming the company won't switch its main development language from C++/C#/Java to a dynamic one what use is there for a dynamic language? What helper tasks can be done…
szabgab
  • 6,202
  • 11
  • 50
  • 64
67
votes
6 answers

When do Ruby instance variables get set?

class Hello @hello = "hello" def display puts @hello end end h = Hello.new h.display I created the class above. It doesn't print anything out. I thought the instance variable @hello was set during the class declaration. But when I…
pez_dispenser
  • 4,394
  • 7
  • 37
  • 47