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
58
votes
11 answers

How to find an item in array which has the most occurrences

How do I find an item in array which has the most occurrences? [1, 1, 1, 2, 3].mode => 1 ['cat', 'dog', 'snake', 'dog'].mode => dog
Til
58
votes
12 answers

How do I auto format Ruby or .erb files in VS Code?

I press ⌥ + ⇧ + F in Visual Studio Code for macOS, the shortcut to Format Document, to format a file called foo.rb or foo.html.erb. Instead of formatting the document it prints out this letter: Ï How do I get it to format the document?
Derek
  • 5,137
  • 9
  • 28
  • 39
58
votes
15 answers

Error installing nokogiri: Failed to build gem native extension & libiconv is missing (OSX)

I try to clone this repo and run bundle install. The bundle process failed and throw this error: ... Installing nokogiri 1.6.2.1 with native extensions Building nokogiri using packaged libraries. Gem::Ext::BuildError: ERROR: Failed…
Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98
58
votes
4 answers

Can I use `else if` over `elsif`?

Is it safe to use else if over elsif? Is it better to use elsif because it follows Ruby's typing convention? Or is this a preference? This is a piece of code taken from a book. I added extra end keywords and swapped elsif keywords with else…
PrimRock
  • 1,076
  • 2
  • 15
  • 27
58
votes
15 answers

How can I clear the terminal in Ruby?

I would like to know to how to do in Ruby what I can do with system("clear") in C. I wrote a program like puts "amit" system("clear") I want the console to be cleared after executing this commnad, but it is not working.
Milan
  • 1,447
  • 5
  • 19
  • 27
58
votes
2 answers

Ruby methods within Javascript within HAML

I have a jQuery script that adds a new field to a form, and this field contains dynamic information from an array. The problem is that I can't figure out how to add an array.each to populate the options of the select field within the javascript…
Josh
  • 603
  • 1
  • 5
  • 6
58
votes
6 answers

ruby super keyword

From what I understand, super keyword invokes a method with the same name as the current method in the superclass of the current class. Below in the autoload method, there is a call to super. I would like to know in which superclass I would find a…
user290870
  • 1,591
  • 3
  • 19
  • 27
58
votes
2 answers

RSpec any_instance deprecation: how to fix it?

In my Rails project I'm using rspec-mocks using any_instance but I want to avoid this deprecation message: Using any_instance from rspec-mocks' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or…
Rowandish
  • 2,655
  • 3
  • 31
  • 52
58
votes
2 answers

Rails Migration: How to increase column data type size by using ROR migration

My users table login column is String type with limit of 40 characters. Now I am planning to increase the limit to 55 characters. Any one please let me know how can we increase this limit by using ROR migration. Thanks, Sravan
Sravan Kumar
  • 673
  • 1
  • 7
  • 12
58
votes
4 answers

How do I make HTTParty ignore SSL?

I'm using a local server to test an application, and make requests to that server from my own machine. The test server's SSL is bad, and HTTParty throws errors because of that. From what I read, HTTParty should ignore SSL by default, but when I try…
Jasper Kennis
  • 3,225
  • 6
  • 41
  • 74
58
votes
1 answer

RSpec: specifying multiple calls to a method with different argument each time

In rspec (1.2.9), what is the correct way to specify that an object will receive multiple calls to a method with a different argument each time? I ask because of this confusing result: describe Object do it "passes, as expected" do foo =…
Wayne Conrad
  • 103,207
  • 26
  • 155
  • 191
58
votes
3 answers

How should I use each_with_object on Hashes?

I would like to use each_with_object on a hash but can't figure out how I should use it. Here is what I have: hash = {key1: :value1, key2: :value2} hash.each_with_object([]) { |k, v, array| array << k } NoMethodError: undefined method `<<' for…
Pierre-Louis Gottfrois
  • 17,561
  • 8
  • 47
  • 71
58
votes
3 answers

Is there simpler (one-line) syntax to alias one class method?

I know I can do the following, and it's just 3 lines: class << self alias :generate :new end But out of curiosity, is there a simpler way (without semicolons) like: class_alias :generate, :new
AJcodez
  • 31,780
  • 20
  • 84
  • 118
58
votes
12 answers

Calculating Median in Ruby

How do I calculate the median of an array of numbers using Ruby? I am a beginner and am struggling with handling the cases of the array being of odd and even length.
tbone
  • 892
  • 1
  • 7
  • 17
58
votes
5 answers

How to force Ruby string to n characters

How to force Ruby string variable output using puts to n characters so that if the variable is longer, it will be truncated, if shorter, it will be expanded by trailing or leading spaces? Is there some standard method to do this?
Paul
  • 25,812
  • 38
  • 124
  • 247
1 2 3
99
100