lazyload ruby and rails extensions


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.