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
69
votes
2 answers

What is a Rakefile?

I have started learning Ruby and just tried out my first hello world program in NetBeans IDE. I have one doubt, I can see that the new project wizard created set of package structure. It had one "Rakefile" in it. What does that mean and what is the…
bragboy
  • 34,892
  • 30
  • 114
  • 171
69
votes
8 answers

Add method to an instanced object

obj = SomeObject.new def obj.new_method "do some things" end puts obj.new_method > "do some things" This works ok. However, I need to do same thing inside an existing method: def some_random_method def obj.new_method "do some things" …
vise
  • 12,713
  • 11
  • 52
  • 64
69
votes
2 answers

Why is __FILE__ uppercase and __dir__ lowercase?

In Ruby 2.0.0-p0, the __dir__ variable was introduced for easy access to the directory of the file currently being executed. Why is __dir__ lowercase when __FILE__ is uppercase?
conradkleinespel
  • 6,560
  • 10
  • 51
  • 87
69
votes
8 answers

Reading the first line of a file in Ruby

I want to read only the first line of a file using Ruby in the fastest, simplest, most idiomatic way possible. What's the best approach? (Specifically: I want to read the git commit UUID out of the REVISION file in my latest Capistrano-deployed…
Craig Walker
  • 49,871
  • 54
  • 152
  • 212
69
votes
3 answers

How to set a file upload programmatically using Paperclip

I have a rake task to seed an application with random data using the faker gem. However, we also have images (like logos) that we want uploaded in this rake task. We already have Paperclip set up, but don't have a way to upload them programmatically…
Jaryl
  • 2,561
  • 1
  • 24
  • 33
69
votes
6 answers

What is the difference between using .exists?, and .present? in Ruby?

I want to make sure I'm using them for the correct occasion and want to know of any subtleties. They seem to function the same way, which is to check to see if a object field has been defined, when I use them via the console and there isn't a whole…
perseverance
  • 6,372
  • 12
  • 49
  • 68
69
votes
6 answers

What is the difference between Ruby and Ruby on Rails?

I have been studying Ruby for the past few days and I have noticed there is Ruby on Rails. What is the difference between the two? Do they work together? Is the syntax the same?
yaar zeigerman
  • 1,107
  • 2
  • 11
  • 17
69
votes
3 answers

to_s vs. to_str (and to_i/to_a/to_h vs. to_int/to_ary/to_hash) in Ruby

I'm learning Ruby and I've seen a couple of methods that are confusing me a bit, particularly to_s vs to_str (and similarly, to_i/to_int, to_a/to_ary, & to_h/to_hash). What I've read explains that the shorter form (e.g. to_s) are for explicit…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
69
votes
5 answers

Ruby - Difference between Array#<< and Array#push

From examining the documentation for Ruby 1.9.3, both Array#<< and Array#push were designed to implement appending an element to the end of the current array. However, there seem to be subtle differences between the two. The one I have encountered…
RavensKrag
  • 895
  • 1
  • 7
  • 9
68
votes
18 answers

Rails, MySQL and Snow Leopard

I upgraded to Snow Leopard using the disc we got at WWDC. Trying to run some of my rails apps now complains about sql (in /Users/coneybeare/Projects/Ambiance/ambiance-server) !!! The bundled mysql.rb driver has been removed from Rails 2.2.…
coneybeare
  • 33,113
  • 21
  • 131
  • 183
68
votes
5 answers

Allow public connections to local Ruby on Rails Development Server

I am setting up a RoR development environment on a Windows machine. I was wondering how I can set it up so a few friends of mine can have access to the web server and monitor the progress? It would only be 2 or 3 people connecting at anytime time…
Dan
  • 2,299
  • 2
  • 20
  • 41
68
votes
3 answers

Validate attribute only if it present (only if user fill in it)

I need validate some attributes ONLY if they are not empty. For example the user may have a logo. If we try to load it - validation should work. If we simply update the user's data without the logo, validation must be skipped. Now i have: The form…
prosto.vint
  • 1,403
  • 2
  • 17
  • 30
68
votes
7 answers

Get current ruby process memory usage

I'd like to format my Logger output to include the current memory usage, for part of a long-running process. Is there anything built-in to Ruby for this, a bit like PHP's memory_get_usage()? Or do I have to execute some shell commands to get it…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
68
votes
4 answers

When to use each method of launching a subprocess in Ruby

1. `` The Backtick defined in Kernel 1. a) %x{} Percent X < alternate syntax for The Backtick defined in parse.y, see discussion 2. system() Kernel#system 3. fork() Kernel#fork, Process#fork 4. open() open a pipe Kernel#open 4.a.…
Alec Wenzowski
  • 3,878
  • 3
  • 25
  • 40
68
votes
15 answers

Common Ruby Idioms

One thing I love about ruby is that mostly it is a very readable language (which is great for self-documenting code) However, inspired by this question: Ruby Code explained and the description of how ||= works in ruby, I was thinking about the ruby…
DanSingerman
  • 36,066
  • 13
  • 81
  • 92