Skip to content

Instantly share code, notes, and snippets.

@iamjwc
Created April 26, 2011 15:00
Show Gist options
  • Save iamjwc/942440 to your computer and use it in GitHub Desktop.
Save iamjwc/942440 to your computer and use it in GitHub Desktop.
[~/programming/sinatra]$ irb
ruby-1.8.7-p330 :001 > class Array; def save_map(&blk); self.instance_variable_set(:@map_blk, blk) end; def call_saved_map; self.map(&self.instance_variable_get(:@map_blk)) end end
=> nil
ruby-1.8.7-p330 :002 > a = [1,2,3]
=> [1, 2, 3]
ruby-1.8.7-p330 :003 > a.save_map {|i| i * 2 }
=> #<Proc:0x00000001003463a8@(irb):3>
ruby-1.8.7-p330 :004 > a
=> [1, 2, 3]
ruby-1.8.7-p330 :005 > a.call_saved_map
=> [2, 4, 6]
ruby-1.8.7-p330 :006 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment