Created
          December 23, 2013 07:04 
        
      - 
      
- 
        Save TimLang/8092775 to your computer and use it in GitHub Desktop. 
    multi-dimensional array map
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Object | |
| def deep_map(&block); yield(self) end | |
| end | |
| class Array | |
| def deep_map(&block); map{|e| e.deep_map(&block)} end | |
| end | |
| or | |
| class Object | |
| def deep_map &block | |
| if self.respond_to?(:inject) | |
| self.inject([]) do |result, ary| | |
| result << ary.deep_map(&block) | |
| end | |
| else | |
| block.call(self) | |
| end | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment