module Enumerable def collect_with_index(i=0) collect{|elm| yield(elm, i+=1)} end alias map_with_index collect_with_indexend #Example use : ree-1.8.7-2010.01 > ['ruby', 'rails', 'sandip'].map_with_index{ |w,i| [w, i] } #=> [["ruby", 1], ["rails", 2], ["sandip", 3]] ree-1.8.7-2010.01 > ['ruby', 'rails', 'sandip'].collect_with_index{ |w,i| [w, i] } #=> [["ruby", 1], ["rails", 2], ["sandip", 3]] #By default index starts from zero to specify custom … Continue reading Extend enumerable to add method collect_with_index
Month: February 2010
Fix/Solution for NoMethodError? (undefined method `controller_name’ for nil:NilClass)
This error appears when same action gets called twice. There might be chances to have controller with same name twice inside app as well as pluginsIn my case the error appeared while migrating from rails 2.1 to 2.3.Application was having application.rb and application_controller.rbFiles deleted:trunk/app/controllers/application.rbAnd that solved problem !
Online ruby Programming useful website links
1. Ruby http://tryruby.org2. Hpricot http://hpricot.com3. Regular expressions http://rubular.com4. Exceptions http://hoptoadapp.com/5. Application Performance http://newrelic.com6. Ruby Doc http://www.ruby-doc.org/7. Rails API http://api.rubyonrails.org/8. Ruby gems sources http://rubyforge.org / http://gems.github.com / http://gemcutter.org9. Listing remote gems from source gem list --remote --source http://gems.github.com10. List of Rails Plugins http://wiki.rubyonrails.org/rails/pages/Pluginshttp://www.agilewebdevelopment.com/plugins
