Posted By

avioli on 02/09/11


Tagged

rails ruby


Versions (?)

lazyload ruby and rails extensions


 / Published in: Rails
 

URL: http://stackoverflow.com/questions/842359/extending-core-ruby-classes-when-in-rails#answer-842851

  1. # by August Lilleaas
  2. # config/initializers/app.rb
  3. Dir[File.join(Rails.root, "lib", "core_ext", "*.rb")].each {|l| require l }
  4.  
  5. # lib/core_ext/array.rb
  6. class Array
  7. def to_sentence_with_block(*args, &block)
  8. if block_given?
  9. # do something...
  10. # to_sentence_without_block(*args) perhaps?
  11. else
  12. to_sentence_without_block(*args)
  13. end
  14. end
  15. alias_method_chain :to_sentence, :block
  16. end

Report this snippet  

You need to login to post a comment.