Skip to content

Instantly share code, notes, and snippets.

@morganp
Forked from Whoops/flatten.rb
Created September 2, 2010 02:14

Revisions

  1. @Whoops Whoops created this gist Sep 2, 2010.
    3 changes: 3 additions & 0 deletions flatten.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    require 'pp'
    a=[1,[2,[3]],4,5,[6,7,[8,9]]]
    pp a.inject([]){|b,x| if Array===x then x.each {|y| b << y } else b << x end;b;}
    2 changes: 2 additions & 0 deletions numeric.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    #ruby numeric.rb 10000000.12355
    a,b=ARGV[0].split('.');p a.reverse.gsub(/(\d{3})(?=\d)/,'\1,').reverse + "." + b
    2 changes: 2 additions & 0 deletions resolve.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    #ruby resolve.rb "Enumerable::Enumerator"
    puts ARGV[0].split('::').inject(Kernel){|obj,str|obj.const_get(str)}