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].
ruby
229,224
questions
2305
votes
29
answers
1.1m
views
How to write a switch statement in Ruby
How do I write a switch statement in Ruby?
1532
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?
1266
votes
22
answers
651k
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?
1235
votes
11
answers
817k
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?
1217
votes
22
answers
448k
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?
1214
votes
15
answers
336k
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 ...
1155
votes
20
answers
551k
views
What is attr_accessor in Ruby?
I am having a hard time understanding attr_accessor in Ruby.
Can someone explain this to me?
1128
votes
33
answers
574k
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.
1094
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 ...
1063
votes
11
answers
230k
views
Understanding the Rails Authenticity Token
What is the Authenticity Token in Rails?
1052
votes
8
answers
594k
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?
1012
votes
6
answers
193k
views
class << self idiom in Ruby
What does class << self do in Ruby?
986
votes
8
answers
490k
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 ...
985
votes
6
answers
355k
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?
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"
...