4 kyu

Add _ - accessors to Hash

576 of 600ineiti

Description:

Instead of having to access values in hash by

h[:one]

or

h["one"]

write a method_missing that allows to use

h._one

both for reading and writing. It should

  • first check for a key as a symbol, then for a key as a string
  • return nil if neither was found
  • return the value upon setting a new one
  • add a new key as a symbol if it doesn't exist yet
  • update whatever key is there, either symbol or string
Metaprogramming
Algorithms

Stats:

CreatedJul 25, 2013
PublishedJul 26, 2013
Warriors Trained1741
Total Skips770
Total Code Submissions18353
Total Times Completed600
Ruby Completions576
Total Stars41
% of votes with a positive feedback rating65% of 72
Total "Very Satisfied" Votes37
Total "Somewhat Satisfied" Votes20
Total "Not Satisfied" Votes15
Ad
Contributors
  • ineiti Avatar
Ad