Project

General

Profile

Feature #10726 ยป implement_set#power.patch

gogotanaka (Kazuki Tanaka), 01/10/2015 01:17 AM

View differences:

lib/set.rb
513 513
    end
514 514
  end
515
  # Returns set of all subsets of +self+.
516
  #
517
  # e.g.:
518
  #
519
  #   require 'set'
520
  #   set = Set[1, 2].power
521
  #   p set     # => #<Set: {#<Set: {}>,
522
  #             #            #<Set: {1}>,
523
  #             #            #<Set: {2}>,
524
  #             #            #<Set: {1, 2}>}>
525
  def power
526
    (0 .. 2 ** length - 1).map { |n|
527
      select.with_index { |_, i| (n >> i) & 1 == 1 }.to_set
528
    }.to_set
529
  end
530

  
515 531
  InspectKey = :__inspect_key__         # :nodoc:
516 532
  # Returns a string containing a human-readable representation of the
517
-