Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxfight3r/39b9f6b1db38cc617ac0 to your computer and use it in GitHub Desktop.
Save tuxfight3r/39b9f6b1db38cc617ac0 to your computer and use it in GitHub Desktop.
ruby lambda fun
#Basic lambda Hello World
irb(main):122:0> test=lambda{"Hello World"}
=> #<Proc:0x00000001393e28@(irb):122 (lambda)>
irb(main):123:0> test.call
=> "Hello World"
#lambda function to remove nth object from an array
irb(main):115:0> str=lambda {|arr,div| arr.each_with_index.map{|x,i| i+=1; next if i % div == 0; x}.compact }
=> #<Proc:0x00000001570a70@(irb):115 (lambda)>
irb(main):116:0> str.call((0..20).to_a, 3)
=> [0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment