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

What is a regex to match a string NOT at the end of a line?

The regex /abc$/ will match an abc that does appear at the end of the line. How do I do the inverse? I want to match abc that isn't at the end of a line. Furthermore, I'm going to be using the regex to replace strings, so I want to capture only abc,…
Tim
  • 6,079
  • 8
  • 35
  • 41
58
votes
4 answers

Rails optional argument

I have a class class Person attr_accessor :name,:age def initialize(name,age) @name = name @age = age end end I'd like to make the age optional so its 0 if its not passed, or the name to be blank if not passed Ive…
Tarang
  • 75,157
  • 39
  • 215
  • 276
58
votes
3 answers

Why is Ruby unable to verify an SSL certificate?

This is my first time trying to use the XMLRPC::Client library to interact with a remote API and I keep receiving this error: warning: peer certificate won't be verified in this SSL session Searching around I've found loads of people that have…
Sam Stelfox
  • 745
  • 1
  • 6
  • 12
58
votes
8 answers

Comparing two arrays ignoring element order in Ruby

I need to check whether two arrays contain the same data in any order. Using the imaginary compare method, I would like to do: arr1 = [1,2,3,5,4] arr2 = [3,4,2,1,5] arr3 = [3,4,2,1,5,5] arr1.compare(arr2) #true arr1.compare(arr3) #false I used…
SimonMayer
  • 4,719
  • 4
  • 33
  • 45
58
votes
12 answers

diff a ruby string or array

How do I do a diff of two strings or arrays in Ruby?
Josh Moore
  • 13,338
  • 15
  • 58
  • 74
58
votes
8 answers

Rails POST, PUT, GET

After I generate a scaffold, Rails gives me the ability to POST to items.xml which will create a new item. A GET to items.xml will simply list them all. Where does Rails specify which method in the controller (create or index, respectively) will be…
geowa4
  • 40,390
  • 17
  • 88
  • 107
58
votes
5 answers

How to filter parameters in rails?

Rails has built in log filtering so you don't log passwords and credit cards. Works great for that but when you want to trigger a custom log (like to email) and send your own params or other data along with it, the parameters are obviously not…
chrishomer
  • 4,900
  • 5
  • 38
  • 52
58
votes
2 answers

How do I use the Enumerable mixin in my class?

I have a class called Note, which includes an instance variable called time_spent. I want to be able to do something like this: current_user.notes.inject{|total_time_spent,note| total_time_spent + note.time_spent} Is this possible by mixing in the…
ben
  • 29,229
  • 42
  • 124
  • 179
58
votes
3 answers

Ruby on Rails: errors.add_to_base vs. errors.add

I have read that errors.add_to_base should be used for errors associated with the object and not a specific attribute. I am having trouble conceptualizing what this means. Could someone provide an example of when I would want to use each? For…
Tony
  • 18,776
  • 31
  • 129
  • 193
58
votes
6 answers

Running Rake tasks in Rspec Tests

I am building up an integration test suite and there is one bit of logic that I need to have a clean database for. How can I run the db:test:purge task inside of one of my tests? I am using: ruby 1.9.2, rails 3.0.9, rspec 2.6
xentek
  • 2,555
  • 2
  • 20
  • 12
58
votes
7 answers

ActiveModel::MissingAttributeError occurs after deploying and then goes away after a while

I have a Rails 3.0.9 app that, once it is deployed, suffers from a bunch of ActiveModel::MissingAttributeErrors that crop up causing 500s. The errors occur fairly randomly, sometimes a page will load, other times it won't, but the attributes are all…
philnash
  • 70,667
  • 10
  • 60
  • 88
58
votes
5 answers

How do I convert hash keys to method names?

This is my hash: tempData = {"a" => 100, "here" => 200, "c" => "hello"} I need to access the hash keys as a method like: tempData.a #100 tempData.here # 200
Sreeraj
  • 2,690
  • 6
  • 26
  • 37
58
votes
3 answers

What is the difference between %w{} and %W{} upper and lower case percent W array literals in Ruby?

%w[ ] Non-interpolated Array of words, separated by whitespace %W[ ] Interpolated Array of words, separated by whitespace Usage: p %w{one one two three 0 1 1 2 3} # = > ["one", "one", "two", "three", "0", "1", "1", "2", "3"] p %W{one one two…
RyanScottLewis
  • 13,396
  • 16
  • 56
  • 84
58
votes
5 answers

how to use ruby " case ... when " with inequalities?

can you do this in ruby? it seems to "miss" the cases with inequalities case myvar when myvar < -5 do somethingA when -5..-3 do special_something_XX when -2..-1 do special_something_YY when myvar == 0 do somethingB when myvar…
jpw
  • 18,697
  • 25
  • 111
  • 187
58
votes
6 answers

What does `if __FILE__ == $0` mean in Ruby

if __FILE__ == $0 $:.unshift File.join(File.dirname(__FILE__),'..') I found this code in Ruby, what's the meaning?
mlzboy
  • 14,343
  • 23
  • 76
  • 97
1 2 3
99
100