← Back to Upcase

Learning Ruby while reading Factory Girl's Source Code


(Antonio Irizarry) #1

Have a question regarding a method being used in Factory Girl’s generator.rb file.
https://github.com/thoughtbot/factory_girl_rails/blob/master/lib/factory_girl_rails/generator.rb

Here is the Snippet of Code…
What is the rails_option method performing? Why is it being called as if it were a hash?

def test_framework
  rails_options[:test_framework]
end

def factory_girl_disabled?
  rails_options[:factory_girl] == false
end

def rails_options
  @generators.options[:rails]
end

-Thank you!


(Patrik Bóna) #2

It is implicit return of ruby. That code is equivalent of:

def rails_options
  return @generators.options[:rails] # but using explicit return when it is not need is not a ruby way ;)
end