Module: RubyClassesExtensions::HashExtensions

Included in:
Hash
Defined in:
lib/ruby_classes_extensions/hash_extensions.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby_classes_extensions/hash_extensions.rb', line 3

def self.included(base)
  base.class_eval do
    #return new Hash. This hash return humanized value of key(except moments when key has set another value)
    #example
    # a = Hash.humanized
    # a[:vladimir] = 'Vlad'
    #
    # a[:misha] will return 'Misha'
    # a[:vladimir] will return 'Vlad'(because this value set manually)
    # f["fred_loves_new_cars"] will return "Fred loves new cars"
   def self.humanized
      self.new{|hash,k| hash[k] = k.to_s.humanize}
   end
  end
end