18
05

Randomizzare un array con ruby on rails

postato da Administrator, in Ruby on rails, tutorials.

Questo tutorial ci mostra come randomizzare gli elementi di un array con ruby on rails

# external...  
def shuffle(arr)  
  arr.sort {|a, b| rand <=> 0.5 }  
end 
 
# ...or as part of Array  
class Array 
  def shuffle  
    self.sort {|a, b| rand <=> 0.5 }  
  end 
end  

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Reddit
  • scuttle
  • Smarking
  • Spurl
  • YahooMyWeb
  • DZone
  • Internetmedia
  • Snap2r
  • Technorati

Letto:582 volte

Correlati

    No related posts

Leave a Reply

web tracker