Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl/monkeypatches.rb,
lib/dsl/monkeypatches.rb

Overview

Enchancement of Hash class to generate random hash of the given size. The hash elements are instances of the samples given. The keys are in the range (‘a’..‘z’). By default, there is a hash having strings and fixnums as values.

Instance Method Summary collapse

Instance Method Details

#(size: 64, samples: ["", 1000]) ⇒ Hash Also known as: any

TODO:

Do we really need to append randoms? Isn’t {}.∀ | {:foo ⇒ 42} clearer?

Note:

When called on non-empty hash, the random elements are added to the existing.

Generates random sample of Hash.

Examples:

To create a hash of three elements:

{}. size: 3
# ⇒ {
#   "pcnoljbhibgjywosztzheuimqfawzi" => 821,
# "rjdrhidkhrowsonpsmaskdjfbhpuwunh" => " рлшеALя н нмкж0отDщ5 MеьFKB1Mъ5",
# "zbalqtiqysdfbartnebvkmwzvudxkzmk" => "Dе904KшNщуO7EывхJбMUV йN Zч энж"
# }


130
131
132
133
134
135
136
# File 'lib/dsl/monkeypatches.rb', line 130

def (size: 64, samples: ["", 1000])
  self.dup.tap { |v|
    size.times {
      v["".(:symbols => [*('a'..'z')])] = ::Kernel::random(:samples => samples)
    }
  }
end