Miika Vuorio Miika Vuorio - 1 year ago 88
Ruby Question

What is the meaning of the keyword "do", in ruby?

I'm a real noob to ruby on rails. I started yesterday so yea, but I've seen a couple of "do" in ruby and I couldn't find a really good answer for it. A place where I saw a do was in the gemfile.

group :development, :test do
gem 'rspec-rails'
gem 'rspec-its'
gem 'simplecov', :require => false
gem 'guard-rspec'
gem 'spork-rails'
gem 'guard-spork'
gem 'childprosess'
gem 'rails-erd'
gem 'pry-rails'
gem 'guard-rails'
gem 'guard-livereload'
gem 'guard-bundler'

I know what this code does, but I don't know the purpose of do. I have my guesses, but I want them confirmed or denied by someone who knows more than me.

Answer Source

The do keyword is used together with the end keyword to delimit a code block.

More info on the difference of do end with brackets may be found here: http://ruby-doc.org/docs/keywords/1.9/files/keywords_rb.html#M000015

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download