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
61
votes
8 answers

Test whether a variable equals either one of two values

I want to test whether a equals 1 or 2 I could do a == 1 || a == 2 but this requires repeating a (which would be annoying for longer variables) I'd like to do something like a == (1 || 2), but obviously this won't work I could do [1,…
Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
61
votes
3 answers

How do I force ActiveRecord to reload a class?

I'm creating a bunch of migrations, some of which are standard "create table" or "modify table" migrations, and some of which modify data. I'm using my actual ActiveRecord models to modify the data, a la: Blog.all.each do |blog| …
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
61
votes
3 answers

What's the difference between "include_examples" and "it_behaves_like"?

In RSpec, what's the difference between it_behaves_like and include_examples? The documentation says: include_examples — include(s) the examples in the current context it_behaves_like "name" — include(s) the examples in a nested context But what…
GMA
  • 5,816
  • 6
  • 51
  • 80
61
votes
4 answers

Best way to handle data attributes in Slim

I was evaluating Slim as a replacement for HAML in a personal project, and it doesn't appear to handle HTML5 data attributes as gracefully as HAML. I was hoping someone may have also run into this, or may have known about an option/syntax I haven't…
mmoss
  • 713
  • 1
  • 5
  • 5
61
votes
2 answers

Forking a gem for a Rails project

I've found myself twice in this situation: I install a gem on my system and start using it from my Rails project. Eventually I need to make some changes to that gem. How should I proceed? Ideally I'd like to check out the source code of that gem…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
61
votes
6 answers

How to encode media in base64 given URL in Ruby

I'm trying to upload an image to PingFM. Their documentation says: media – base64 encoded media data. I can access this image via the URL. I tried (practically guessed) this: ActiveSupport::Base64.encode64(open("http://image.com/img.jpg")) But I…
Ramon Tayag
  • 15,224
  • 9
  • 43
  • 69
61
votes
9 answers

Open the default browser in Ruby

In Python, you can do this: import webbrowser webbrowser.open_new("http://example.com/") It will open the passed in url in the default browser Is there a ruby equivalent?
Gareth Simpson
  • 36,943
  • 12
  • 47
  • 50
61
votes
13 answers

How to get the number of days in a given month in Ruby, accounting for year?

I'm sure there's a good simple elegant one-liner in Ruby to give you the number of days in a given month, accounting for year, such as "February 1997". What is it?
Teflon Ted
  • 8,696
  • 19
  • 64
  • 78
61
votes
6 answers

Check if a hash's keys include all of a set of keys

I'm looking for a better way to do if hash.key? :a && hash.key? :b && hash.key? :c && hash.key? :d preferably something like hash.includes_keys? [ :a, :b, :c, :d ] I came up with hash.keys & [:a, :b, :c, :d] == [:a, :b, :c, :d] but I…
Greg Guida
  • 7,302
  • 4
  • 30
  • 40
61
votes
10 answers

Pure-Ruby concurrent Hash

What's the best way to implement a Hash that can be modified across multiple threads, but with the smallest number of locks. For the purposes of this question, you can assume that the Hash will be read-heavy. It must be thread-safe in all Ruby…
Yehuda Katz
  • 28,535
  • 12
  • 89
  • 91
61
votes
5 answers

How I can check if an object is null in ruby on rails 2?

I want to check when my object @objectname is not equal to null to show the values of the @objectname else to show that no values found. I tried this: <% if (@objectname != null) then %> but I'm getting an error.
George Panayi
  • 1,768
  • 6
  • 26
  • 42
60
votes
2 answers

Check for multiple items in array using .include? -- Ruby Beginner

Is there a better way to write this: if myarray.include? 'val1' || myarray.include? 'val2' || myarray.include? 'val3' || myarray.include? 'val4'
Hopstream
  • 6,391
  • 11
  • 50
  • 81
60
votes
9 answers

Can Mustache Templates do template extension?

I'm new to Mustache. Many templating languages (e.g., Django / Jinja) will let you extend a "parent" template like so... base.html {% block content %}{% endblock %} frontpage.html {% extends…
Chris W.
  • 37,583
  • 36
  • 99
  • 136
60
votes
6 answers

How to make Rails 3.1 use SASS (Over SCSS) as the default?

Having a hard time figuring out how to make SASS, not SCSS, as the default for stylesheets. I've tried making a sass_config.rb file with this: Sass::Plugin.options[:syntax] = :sass Sass::Plugin.options[:style] = :compressed I've also tried adding…
krainboltgreene
  • 1,841
  • 2
  • 17
  • 25
60
votes
4 answers

Check if URL exists in Ruby

How would I go about checking if a URL exists using Ruby? For example, for the URL https://google.com the result should be truthy, but for the URLs https://no.such.domain or https://stackoverflow.com/no/such/path the result should be falsey
Shrikanth Hathwar
  • 1,140
  • 4
  • 14
  • 25