0

I'm just learning Ruby/Rails. Consider this excerpt from a Gemfile:

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

What is group in the ruby language? I initially thought of a function but why would the thing that the function returns be followed by a do - end block?

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
ben
  • 5,671
  • 4
  • 27
  • 55

1 Answers1

1

It is just a plain old function, it's not part of the language. See http://bundler.io/groups.html

Functions can accept blocks (the do/end part). The function's return value isn't "followed" by do/end, the do/end is one of the arguments to the function, along with the symbol :production.

Similarly, gem is also just a function, not a part of Ruby.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • Interesting. TBH I only skimmed the site you referenced and could not find information saying it's not part of ruby. However given your reputation I'm blindly accepting this answer. – ben Dec 28 '14 at 05:20
  • You don't have to believe me. Just try running `irb` and type `group`. – user229044 Dec 28 '14 at 05:24
  • Okay I did this. Now I realized I might have mixed something up. When you say "just a function, not part of Ruby" you mean it is no native ruby function but it is a function declared in the ruby language right? (Initially I thought you meant no ruby is involved at all) – ben Dec 28 '14 at 05:28
  • It's not a built-in function, but it is part of a library (Ruby Gems) which has been included with Ruby since version 1.9. It is not a "native" function, it is implemented in plain old Ruby. [Here, to be specific](https://github.com/rubygems/rubygems/blob/681e214a30509029f11e329710a2b10b024b61a5/lib/rubygems/request_set/gem_dependency_api.rb). – user229044 Dec 28 '14 at 05:31
  • Actually, it's not a function at all, it's a method. – Jörg W Mittag Dec 28 '14 at 05:34
  • @JörgWMittag For simplicity's sake, I didn't feel the need to bring this up, but yes. – user229044 Dec 28 '14 at 05:39