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

Rails, Ruby, how to sort an Array?

in my rails app I'm creating an array like so: @messages.each do |message| @list << { :id => message.id, :title => message.title, :time_ago => message.replies.first.created_at } end After making this array I would like to then sort…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
68
votes
5 answers

How to rename a file in Ruby?

Here's my .rb file: puts "Renaming files..." folder_path = "/home/papuccino1/Desktop/Test" Dir.glob(folder_path + "/*").sort.each do |f| filename = File.basename(f, File.extname(f)) File.rename(f, filename.capitalize +…
delete
68
votes
2 answers

Why can't a variable name end with `?` while a method name can?

A method name can end with a question mark ? def has_completed? return count > 10 end but a variable name cannot. What is the reason for that? Isn't it convenient to have variable names ending the same way too? Given that we usually can't tell…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
68
votes
7 answers

what's different between each and collect method in Ruby

From this code I don't know the difference between the two methods, collect and each. a = ["L","Z","J"].collect{|x| puts x.succ} #=> M AA K print a.class #=> Array b = ["L","Z","J"].each{|x| puts x.succ} #=> M AA K print b.class #=> Array
mko
  • 21,334
  • 49
  • 130
  • 191
68
votes
5 answers

How to "soft delete" user with Devise

I currently use Devise for user registration/authentication in a Rails project. When a user wants to cancel their account, the user object is destroyed, which leaves my application in an undesired state. What is the easiest way to implement a "soft…
slhck
  • 36,575
  • 28
  • 148
  • 201
68
votes
7 answers

Ruby craziness: Class vs Object?

I just started playing with JRuby. This is my first ruby post. I had a hard time understanding classes vs objects in Ruby. It doesnt mean like what classes & objects in other Object oriented laguages. for an example Class.is_a? Object returns…
RameshVel
  • 64,778
  • 30
  • 169
  • 213
68
votes
3 answers

Changing field separator/delimiter in exported CSV using Ruby CSV

Is it possible to change the default field separator from comma to to some other character, e.g '|' for exporting?
Vincent
  • 16,086
  • 18
  • 67
  • 73
68
votes
1 answer

Rails: difference between ENV.fetch() and ENV[]

What is the difference between these two syntax: ENV.fetch("MY_VAR") ENV['MY_VAR'] I've seen Rails 5 use both versions of these in difference places and can't figure out what the difference is (apart from the first one being more characters to…
Winker
  • 805
  • 2
  • 7
  • 9
68
votes
4 answers

:as in rails routes.rb

In config/routes.rb, I tried both: root :to => 'things#index', :as => 'things' and root :to => 'things#index' When I hit http://localhost:3000/, both approaches work, and nothing seems to be different. What is the :as option used for?
ryanprayogo
  • 11,587
  • 11
  • 51
  • 66
68
votes
5 answers

How do I set a blank value for an f.select form field

I am using the following to allow my users to select their sex in their profile. <%= f.select (:sex, %w{ Male Female }) %> How would I create a blank value that the list would default to if nothing has been passed to the user.sex column? I am…
bgadoci
  • 6,363
  • 17
  • 64
  • 91
68
votes
2 answers

What does the Ruby method 'to_sym' do?

What does the to_sym method do? What is it used for?
keruilin
  • 16,782
  • 34
  • 108
  • 175
68
votes
3 answers

Sinatra vs. Rails

I've worked through some of the Sinatra and Rails samples, but I'm having a hard time figuring out which features belong to which technology. What specifically do I gain by using Sinatra/Rails? Is it just ActionPack/ActionView? Correct me if I'm…
LoveMeSomeCode
  • 3,888
  • 8
  • 34
  • 48
68
votes
7 answers

How can I count the number of records that have a unique value in a particular field in ROR?

I have a record set that includes a date field, and want to determine how many unique dates are represented in the record set. Something like: Record.find(:all).date.unique.count but of course, that doesn't seem to work.
Brent
  • 16,259
  • 12
  • 42
  • 42
68
votes
5 answers

Check if an integer is within a range

Is there a simple way to evaluate whether an integer is within that range using the (2..100) syntax. For example, say I wanted to evaluate as true if my integer x = 100, and my range is (0..200), I'm just looking for the simple, concise ruby-way of…
JP Silvashy
  • 46,977
  • 48
  • 149
  • 227
68
votes
12 answers

Why is this RMagick call generating a segmentation fault?

I've been banging my head against the wall for the better part of an hour trying to figure out what's going wrong here, and I'm sure (or rather hoping) it's something fairly obvious that I'm overlooking. I'm using Ruby 1.9.1, Sinatra 1.0, and…
Grant Heaslip
  • 967
  • 2
  • 10
  • 16