Skip to main content
Filter by
Sorted by
Tagged with
2310 votes
29 answers
1.1m views

How to write a switch statement in Ruby

How do I write a switch statement in Ruby?
readonly's user avatar
  • 353k
1536 votes
28 answers
1.2m views

How to check if a value exists in an array in Ruby

I have a value 'Dog' and an array ['Cat', 'Dog', 'Bird']. How do I check if it exists in the array without looping through it? Is there a simple way of checking if the value exists, nothing more?
user211662's user avatar
  • 18.4k
1266 votes
23 answers
652k views

How to call shell commands from Ruby

How do I call shell commands from inside of a Ruby program? How do I then get output from these commands back into Ruby?
CodingWithoutComments's user avatar
1236 votes
11 answers
824k views

How to convert a string to lower or upper case in Ruby

How do I take a string and convert it to lower or upper case in Ruby?
Heat Miser's user avatar
  • 19.7k
1219 votes
22 answers
452k views

How to pass command line arguments to a rake task

I have a rake task that needs to insert a value into multiple databases. I'd like to pass this value into the rake task from the command line, or from another rake task. How can I do this?
Tilendor's user avatar
  • 48.8k
1217 votes
15 answers
338k views

How to understand nil vs. empty vs. blank in Ruby

I find myself repeatedly looking for a clear definition of the differences of nil?, blank?, and empty? in Ruby on Rails. Here's the closest I've come: blank? objects are false, empty, or a ...
Arrel's user avatar
  • 13.6k
1160 votes
20 answers
554k views

What is attr_accessor in Ruby?

I am having a hard time understanding attr_accessor in Ruby. Can someone explain this to me?
dennismonsewicz's user avatar
1129 votes
33 answers
575k views

How do I get the current absolute URL in Ruby on Rails?

How can I get the current absolute URL in my Ruby on Rails view? The request.request_uri only returns the relative URL.
Jakub Arnold's user avatar
  • 86.9k
1095 votes
13 answers
282k views

How to make --no-ri --no-rdoc the default for gem install?

I don't use the RI or RDoc output from the gems I install in my machine or in the servers I handle (I use other means of documentation). Every gem I install installs RI and RDoc documentation by ...
Ricardo Acras's user avatar
1064 votes
11 answers
231k views

Understanding the Rails Authenticity Token

What is the Authenticity Token in Rails?
Ricardo Acras's user avatar
1055 votes
8 answers
599k views

Ruby: How to install a specific version of a ruby gem?

Using the command-line gem tool, how can I install a specific version of a gem?
mjs's user avatar
  • 65k
1014 votes
6 answers
193k views

class << self idiom in Ruby

What does class << self do in Ruby?
randombits's user avatar
  • 48.1k
988 votes
8 answers
493k views

What does %w(array) mean?

I'm looking at the documentation for FileUtils. I'm confused by the following line: FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6' What does the %w mean? Can you point me to the ...
Dane O'Connor's user avatar
988 votes
6 answers
357k views

Why is it bad style to `rescue Exception => e` in Ruby?

Ryan Davis’s Ruby QuickRef says (without explanation): Don’t rescue Exception. EVER. or I will stab you. Why not? What’s the right thing to do?
John's user avatar
  • 29.9k
880 votes
10 answers
1.0m views

How to check whether a string contains a substring in Ruby

I have a string variable with content: varMessage = "hi/thsid/sdfhsjdf/dfjsd/sdjfsdn\n" "/my/name/is/balaji.so\n" "call::myFunction(int const&)\n" ...
BSalunke's user avatar
  • 11.7k

15 30 50 per page
1
2 3 4 5
15288