Just making a thread to post small little snippets I find useful.
Enumerator#inject method is one method I've discovered very late, but I'm finding it very useful:
a=[-5,2,5,1,4,8,9,6,2,5,5,1,4]
=> [-5, 2, 5, 1, 4, 8, 9, 6, 2, 5, 5, 1, 4]
min = a.inject(0) { |m,i| ( i < m ) ? i : m }
=> -5
max = a.inject(0) { |m,i| ( i > m ) ? i : m }
=> 9
total = a.inject(0) { |m,i| i + m }
=> 47
[Code] Ruby snippets
1 post
• Page 1 of 1
[Code] Ruby snippetsThomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
1 post
• Page 1 of 1
|
Who is online
Users browsing this forum: No registered users and 6 guests